Re: array_push in array maps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/3/06, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
Jonas Said:
>> But when I want to have a value from a special column i a row the
>> followint
>> doesn't work:
>>
>>    $test[$row[2]] = $row[5];
>>
>> Or:
>>
>>    $test[$row(2)] = $row[5];
>>
>> Do I need to do some kind of concatenating?
>>

Ah, Lasso! I coded that in my previous job.  Left it to commit to the
world of PHP, but I saw lots of potential in Lasso 8 (we were in
3/4/5).  Sort of miss it sometimes...*sniff*

Anyway, all of the comments are in the right direction.  A couple
things to fill in the gaps:

PHP Arrays are indeed a "mash-up" like Jochem said.  If you want to
get at an array element using a numerical key, then simply use the
number without any quotes, like so:

echo $array[2];

However if you want to get at an array element using a string key,
then it must be surrounded in quotes (single or double, but see below
for more):

echo $array['my_key'];

Now, single quotes and double quotes are slightly (and also very)
different in PHP.  Read the manual for the details
(http://uk.php.net/manual/en/language.types.string.php), but one thing
to know is that the $ sign is a literal $ sign when it is in a string
surrounded by single quotes; but surround it with double quotes, and
it will help you create a variable (assuming you follow it with legal
variable naming characters).

So if you have a variable:
$lang = 'Lasso';

And try to print it in a string with single quotes, it won't work:
echo 'I used to program in $lang';  //  this prints 'I used to program in $lang'

But around double quotes, all is well:
echo "I used to program in $lang"; //  this prints 'I used to program in Lasso'

And if you have a complex variable within a string and you want to
"help" PHP figure out what's a variable and what's not, use { } to
frame the variable name:
echo "Look at my class {$my_class->get('name')} and my array
{$my_array['key']} !";

Make sense?  The manual explains a lot more, so be sure to read up.

Also, unless Lasso changed in 8+, there's one other thing to remember
about arrays.  In PHP, arrays will keep their order of elements as you
have created it.  IIRC, Lasso never guaranteed this, so you always had
to take extra measure to build your arrays such that you could iterate
through them in a reliable fashion.  No worries in PHP, the order
sticks (and you can of course re-order it).

HTH, Good luck,
John W

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux