Forum Moderators: coopster
In my PHP I many an Ass. array that has the two id's assosiated with each other. ($arr[12]=24)
I don't want the array to treat this as an indexed array. To make it an ass. array would I simply need to put the 12 in quotes?
$number = 12;
$array['s'.$number] = 24;
$nid=$database['id'];
if($nid==$myarray[X]{
do something
}
'X' being exsample varriable representing whatever number the i'm compairing it to and not PHP varriable code(havet figured out yet how/where it's is coming from only where it origionates. That's on my tomorrow's to-do list.
Sarah
(added)
What worries me aboult it is what if I add two arrays together. will it change their indexed numbers? and what if their order is important?
Right now I am kinda behind on my thinking of this due to some tecnical errors dealing with
(Suprise suprise) windows. I'm finaly back up and codeing by remoting into my laptop and just using it. unfortunaltly it is slower and hass less memory then windows.... I'm hoping next week I might feel a bit uncreative and ambitouse one day and decide I have the time and energy to waste on rebuilding my desktop.(That would be a good day or two down the drain)
What worries me aboult it is what if I add two arrays together. will it change their indexed numbers? and what if their order is important?
It may change their indexed numbers, it depends on how you "add" the two arrays together. It's important to understand how it works. Here is a snippet for you to play with and learn from, detailed explanations can be found in the PHP manual for the array_merge() [php.net] function ...
<pre>If the order is important, even appending or prepending a character as I described earlier will still give you the sorting ability you desire. In the example you gave, and in the explanation from lobo235, you will find that the indexed variable already exists, whether you append/prepend a string character or not. So, you check for the index/key existence and code accordingly.
<?php
$array1 = array('zero', 'one', 'two');
$array2 = array('three', 'four', 'five');
$array = $array1 + $array2;
print_r($array);
$array = array_merge($array1, $array2);
print_r($array);
?>
</pre>
foreach($_POST as $key => $val){
(statment that says if the first letter in $key is 'a' and the second is a number)
$_SESSION[$key]=$val;