With an associative array such as that one:
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
I tried accessing to a value using :
$fruits[2];
This gives me a PHP notcie: Undefined offset;
Is there a way around that ?
Thanks
Not if you want to keep it as an associative array. If you want to use numeric key indexes you could do this:
Find out more about
array_values()at the PHP manual.UPDATE: to compare two associative arrays as you mentioned in your comment you can do this (if they have the same keys — if not you should add
isset()checks):Or, to avoid the array_keys function call: