I have an array inside another and I would like to change a value in a key.
//Obtenemos el numero de arrays
$count = array();
for($i = 0; $i < count($passer); $i++)
{
if(array_key_exists($passer[1],$passer[$i])) {
$passer[1] = "hola";
}
$count[] = $passer[$i];
}
//return....
return $count;
I need to change entries where the key is 1 and replace the value.
I have this array output:
array
(
[0]=>array
(
[0]=>81278
[1]=>87364
[2]=>34923
)
[1]=>array
(
[0]=>81278
[1]=>87364
[2]=>34923
)
)
but I get an error:
Warning: array_key_exists() [function.array-key-exists]:
Any idea what this means and what to do about it?
Several things you should change. First of all the way you write your
forstatement isn’t optimal, it will execute thecount()function upon every iteration, make it like soSecond, your problem. You need to check the
key, which in your case is static1, in the array$passer[$i], so yourarray_key_exists()function should look like thisarray_key_existsexpects the first parameter to be thekeyand second thearrayyou wish to inspect