Is it possible in php to make an array an array key as well?
Example:
array(
array('sample', 'abc') => 'sample value'
);
Is it possible in php to make an array an array key as well?
Example:
array(
array('sample', 'abc') => 'sample value'
);
No, if you read the manual
An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
And :
The key can either be an integer or a string. The value can be of any type.
This is not possible - array keys must be strings or integers.
What you could do is use serialize:
$myArr = array( serialize(array('sample', 'abc')) => 'sample value');
Which will be the same as:
$myArr = array( 'a:2:{i:0;s:6:"sample";i:1;s:3:"abc";}' => 'sample value');
and could be accessed like:
echo $myArr[serialize(array('sample', 'abc'))];
But note that the serialised string which would be the unique identifier for the array item is clearly fairly complicated and almost impossible to type by hand.
PHP arrays can contain integer and string keys while since PHP does not distinguish between indexed and associative arrays. Look for php manual Php Manual
whats wrong with
array(
'sample value' => array('sample', 'abc')
);
you could then do
foreach($array as $string => $child){
...
}
and use the $child
for whatever purpose