array:
A-B-C-D-E-F
J is the son of C. update array so:
A-B-C-J-D-E-F
how do I insert J after C in the array?
I also map the array in a loop (array of comments for display). Will this method take a very long time to perform?
The unshift() method adds new elements to the beginning of an array.
Hence in order to add an element in the array, one of the following methods can be done: By creating a new array: Create a new array of size n+1, where n is the size of the original array. Add the n elements of the original array in this array.
Java Array, by default, does not support to add or remove an element. Therefore, to add an element to the starting of given array, create a new array with the original size + 1, and then assign the new element to be added, and the elements in the original array to the new array.
You can use array_splice() with $length set to 0.
http://de.php.net/manual/en/function.array-splice.php
Example:
$arr_alphabet = array('a', 'b', 'd'); array_splice($arr_alphabet, 2, 0, 'c'); // $arr_alphabet is now: array('a', 'b', 'c', 'd');
Use the splice function to solve this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With