note 37099 added to language.types.array

From: Date: Mon, 03 Nov 2003 10:14:27 +0000
Subject: note 37099 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-59678@lists.php.net to get a copy of this message
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)]; Hope it helps (tm) :-) ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37099 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37099&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37099&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59678) next »