Arrays as keys of arrays
Sometimes you need to associate an array with some kind of value, so you want to do the following:
$a = array (
array (...) => 'good_array',
array (...) => 'big_array',
array (...) => 'green_array'
);
But this is not possible. While you cannot use an array as a key of another array, you still can do this:
$a = array (
serialize (array (...)) => 'good_array',
serialize (array (...)) => 'big_array',
serialize (array (...)) => 'green_array'
);
That’s because serialize() returns strings, which can be a keys of an array. Now if you want to know, whether array $b is good, big or green, you can just do the following:
echo $a[serialize ($b)];
Впервые опубликовано мной на PHP.net в user contributed notes, поэтому english
Ххаккир!
А то ж
ага =))) еще покажите мне пожалуйста эти самые sometimes ;)) а в купе с serialise ;) вообще все прикольно выглядит =)