I have a PHP array like
$arr = array("c_m_email" => "[email protected]");
and I can access the email by
$arr['c_m_email']
But is there another way to just write $arr[0]?
I have a PHP array like
$arr = array("c_m_email" => "[email protected]");
and I can access the email by
$arr['c_m_email']
But is there another way to just write $arr[0]?
Use array_values()
array_values() returns all the values from the array and indexes the array numerically.
$i=0;
$data=array();
foreach($arr as $value){
$data[$i] = $value;
$i++;
}
print_r($data);
array_values() does. So, why would you write the code for that by yourself?
'c_m_email'and not0array_values()as modsfabio said in the answer below and you can access the elements by their index.