Fatal error: Cannot unset string offsets error?
You don't need the unset, you are overriding the outer parameters with the value of the inner array as opposed to the whole array.
$a1 = array("ivr");$a2 = array("ivr2");$a3 = array($a1, $a2);foreach($a3 as $key => $value){ $a3[$key] = $a3[$key][0]; //unset($arr2[$key][0]);};var_dump($a3);
I think you are confused about how foreach works.
foreach($array as $key => $value){ echo $key; echo $value;}
will display the key and value for each key/value pair in an array.
I had this error in a slightly different situation which might prove useful.
unset($search['param']['complete'])
This threw the same error when $search['param'] was still a string instead of an array.
I believe that you have the syntax for the foreach
wrong...it should be $key => $value
where you have $key => $arr2
. So when you have $arr2[$key]
you are looking for element $key
in the nested array $arr2
. $arr2
is referenced by $key
, which is either a string (for an associative array) or an integer (for a non-associative array). $arr2
could also be referenced by $arr[$key]
.