I am trying to insert an array into a 2-dimensional array at a specific position. According the manual, i should be able to do this with array_splice(), but it only deletes the contents of my receiving array without insertion.
I want to get an array with all the values (arrays) of $receivingArray plus the new value (array).
What am I doing wrong??
manual info:
array array_splice ( array &$input , int $offset [, int $length [, mixed $replacement = array() ]] )
If length is specified and is zero, no elements will be removed. If replacement is just one element it is not necessary to put array() around > it, unless the element is an array itself, an object or NULL.
input:
$newArray = array_splice($receivingArray, 0, 0, array($value));
result: $newArray is an empty array
input :
$newArray = array_splice($receivingArray, 1, 0, array($value));
result: $newArray is an empty array
this input:
print_r($receivingArray);
print_r(array($value));
$newArray = array_splice($receivingArray, 1, 1, array($value));
print_r($newArray);
gives: (interestingly)
Array
(
[0] => Array
(
[id] => 1
[primaryID] => 0
[category_id] => 1
[title] => sports
[description] =>
[selected] =>
[level] => 0
)
[1] => Array
(
[id] => 4
[primaryID] => 0
[category_id] => 0
[title] => programming
[description] =>
[selected] =>
[level] => 0
)
)
Array
(
[0] => Array
(
[id] => 2
[primaryID] => 1
[category_id] => 1
[title] => soccer
[description] =>
[selected] =>
[level] => 1
)
)
Array
(
[0] => Array
(
[id] => 4
[primaryID] => 0
[category_id] => 0
[title] => programming
[description] =>
[selected] =>
[level] => 0
)
)
$receivingArray. what you tried(code) and what your expected output. not whole array just a part of it which make sense to all of us.