Hi,
i was wondering what was the best option to store a string in an array.
let me explain: I only need one part of the elements in the array. i.e. i can use the key to store my string, or i can use the value to store the string.
I'll make it clearer with some code:
so my question is: what is the most efficient option to save a string in an array if I only use one part of the elements (key or value) to store the strings.
maybe how i will use that array helps:
I will need to know afterwards, if the string is stored in the array.
wich one is the best?
thanks!
i was wondering what was the best option to store a string in an array.
let me explain: I only need one part of the elements in the array. i.e. i can use the key to store my string, or i can use the value to store the string.
I'll make it clearer with some code:
Code:
$string = 'someString';
$array = array();
//first way to save
$array[$string] = true;//array('someString' => true)
//second way to save
$array[] = $string; //array(0 => 'someString')
maybe how i will use that array helps:
I will need to know afterwards, if the string is stored in the array.
Code:
//i get a string and i want to know if it is already in array in_array($string, $array); isset($array[$string]); ...
thanks!
Comment