[Solved] get key and value from array in php


If you want to access the key, via a known value, then you can simply flip the array with array_flip:

$flipped = array_flip($tokens);

echo $flipped['day']; //86400

Or, just create the array in the correct manner in the first place if you have access to the code that does so:

$tokens = array (
    'year'   => 31536000,
    'month'  => 2592000,
    'week'   => 604800,
    'day'    => 86400,
    'hour'   => 3600,
    'minute' => 60,
    'second' => 1
    );

1

solved get key and value from array in php