Re: [PHP] array_push in array maps

2006-05-03 Thread Brad Bonkoski

I don't believe you 'push' to an associative array like this,
but if you want to add black for example...just do:
$colors['black'] = '#ff';

-Brad

Jonas Rosling wrote:


Need solve another case regarding array maps. Is it possible to insert more
values like with array_push in arrays as bellow?

$colors = array(
 'red' = '#ff',
 'green' = 'X00ff00',
 'blue' = '#ff'
  );

Tanks in advance // Jonas

 



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



Re: [PHP] array_push in array maps

2006-05-03 Thread chris smith

Need solve another case regarding array maps. Is it possible to insert more
values like with array_push in arrays as bellow?

$colors = array(
  'red' = '#ff',
  'green' = 'X00ff00',
  'blue' = '#ff'
   );



Yes.

http://www.php.net/array_push

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] array_push in array maps

2006-05-03 Thread Stut

Jonas Rosling wrote:


Need solve another case regarding array maps. Is it possible to insert more
values like with array_push in arrays as bellow?

$colors = array(
 'red' = '#ff',
 'green' = 'X00ff00',
 'blue' = '#ff'
  );
 



Did you try it? It will work, but there is no need for array_push. All 
you need is...


$colors['yellow'] = '#00';

-Stut

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



Re: [PHP] array_push in array maps

2006-05-03 Thread Stut

Brad Bonkoski wrote:


$colors['black'] = '#ff';



Black? Are you sure?

-Stut

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



Re: [PHP] array_push in array maps

2006-05-03 Thread Brad Bonkoski

or white ;-)

Stut wrote:


Brad Bonkoski wrote:


$colors['black'] = '#ff';




Black? Are you sure?

-Stut




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



RE: [PHP] array_push in array maps

2006-05-03 Thread Jay Blanchard
[snip]
Need solve another case regarding array maps. Is it possible to insert
more
values like with array_push in arrays as bellow?

$colors = array(
  'red' = '#ff',
  'green' = 'X00ff00',
  'blue' = '#ff'
   );
[/snip]

// Append associative array elements
function array_push_associative($arr) {
   $args = func_get_args();
   array_unshift($args); // remove $arr argument
   foreach ($args as $arg) {
   if (is_array($arg)) {
   foreach ($arg as $key = $value) {
   $arr[$key] = $value;
   $ret++;
   }
   }
   }
   
   return $ret;
}

$theArray = array();
echo array_push_associative($theArray, $items, $moreitems) . ' items
added to $theArray.';

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



Re: [PHP] array_push in array maps

2006-05-03 Thread Jochem Maas

Stut wrote:

Brad Bonkoski wrote:


$colors['black'] = '#ff';




Black? Are you sure?


Brad might be wearing his 'negative' goggles today :-)



-Stut



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



Re: [PHP] array_push in array maps

2006-05-03 Thread Jochem Maas

Jonas Rosling wrote:

Need solve another case regarding array maps. Is it possible to insert more


Jonas - in php we just call these things arrays (no 'map') - the array
datatype in php is a mash up (and we love it :-) of the 'oldschool' numerically
indexed array and what is commonly known as a hash (or arraymap) - you can mix
numeric and associative indexes freely (that might seem odd and/or bad when 
coming
from another language but it really is fantastic once you get your head round 
it).


values like with array_push in arrays as bellow?

$colors = array(
  'red' = '#ff',
  'green' = 'X00ff00',
  'blue' = '#ff'
   );



sure:

$colors['grey'] = '#dedede';

the position of the 'inserted' (actually appended) is often not
important - if it is there are plenty of functions that allow you to manipulate
arrays in more a complex fashion e.g. array_splice(). and all sorts of sorting
functions are also available e.g. asort().

check out the vast number of array related function and introductory texts here:

http://php.net/array
http://php.net/manual/language.types.array.php


Tanks in advance // Jonas



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



Re: [PHP] array_push in array maps

2006-05-03 Thread Jonas Rosling
There's allways mutch to learn. :-) I'm very happy for all help I can get.
I ran into another problem when trying to insert a value.
I had no problem with:

$test['something'] = '2500';

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?

Thanks again // Jonas



Den 06-05-03 15.46, skrev Jochem Maas [EMAIL PROTECTED]:

 Jonas Rosling wrote:
 Need solve another case regarding array maps. Is it possible to insert more
 
 Jonas - in php we just call these things arrays (no 'map') - the array
 datatype in php is a mash up (and we love it :-) of the 'oldschool'
 numerically
 indexed array and what is commonly known as a hash (or arraymap) - you can mix
 numeric and associative indexes freely (that might seem odd and/or bad when
 coming
 from another language but it really is fantastic once you get your head round
 it).
 
 values like with array_push in arrays as bellow?
 
 $colors = array(
   'red' = '#ff',
   'green' = 'X00ff00',
   'blue' = '#ff'
);
 
 
 sure:
 
 $colors['grey'] = '#dedede';
 
 the position of the 'inserted' (actually appended) is often not
 important - if it is there are plenty of functions that allow you to
 manipulate
 arrays in more a complex fashion e.g. array_splice(). and all sorts of sorting
 functions are also available e.g. asort().
 
 check out the vast number of array related function and introductory texts
 here:
 
 http://php.net/array
 http://php.net/manual/language.types.array.php
 
 Tanks in advance // Jonas
 
 
 
 

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



Re: [PHP] array_push in array maps

2006-05-03 Thread Brad Bonkoski

What kind of values are stored in $row[2] and $row[5]?

You might need to keep the single quotes
$test['$row[2]'] = $row[5];

-Brad

Jonas Rosling wrote:


There's allways mutch to learn. :-) I'm very happy for all help I can get.
I ran into another problem when trying to insert a value.
I had no problem with:

   $test['something'] = '2500';

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?

Thanks again // Jonas



Den 06-05-03 15.46, skrev Jochem Maas [EMAIL PROTECTED]:

 


Jonas Rosling wrote:
   


Need solve another case regarding array maps. Is it possible to insert more
 


Jonas - in php we just call these things arrays (no 'map') - the array
datatype in php is a mash up (and we love it :-) of the 'oldschool'
numerically
indexed array and what is commonly known as a hash (or arraymap) - you can mix
numeric and associative indexes freely (that might seem odd and/or bad when
coming
from another language but it really is fantastic once you get your head round
it).

   


values like with array_push in arrays as bellow?

$colors = array(
 'red' = '#ff',
 'green' = 'X00ff00',
 'blue' = '#ff'
  );

 


sure:

$colors['grey'] = '#dedede';

the position of the 'inserted' (actually appended) is often not
important - if it is there are plenty of functions that allow you to
manipulate
arrays in more a complex fashion e.g. array_splice(). and all sorts of sorting
functions are also available e.g. asort().

check out the vast number of array related function and introductory texts
here:

http://php.net/array
http://php.net/manual/language.types.array.php

   


Tanks in advance // Jonas

 



   



 



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



Re: [PHP] array_push in array maps

2006-05-03 Thread Jochem Maas

Jonas - what do you mean 'it doesn't work'

(it's like me saying 'the ATM doesn't work and
forgetting to mention I'm trying to withdraw 10,000,000
disney dollars - when I mention that fact the reason is probably
obvious to you why it doesn't work)

Brad Bonkoski wrote:

What kind of values are stored in $row[2] and $row[5]?

You might need to keep the single quotes
$test['$row[2]'] = $row[5];


no this is wrong, unless you want the array key in this case to be
the *exact* *literal* string '$row[2]' - which is unlikely.

Jonas do the following (in the relevant place in your code)
and see what is in $row:

var_dump($row);



-Brad

Jonas Rosling wrote:

There's allways mutch to learn. :-) I'm very happy for all help I can 
get.

I ran into another problem when trying to insert a value.
I had no problem with:

   $test['something'] = '2500';

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?

Thanks again // Jonas



Den 06-05-03 15.46, skrev Jochem Maas [EMAIL PROTECTED]:

 


Jonas Rosling wrote:
  

Need solve another case regarding array maps. Is it possible to 
insert more



Jonas - in php we just call these things arrays (no 'map') - the array
datatype in php is a mash up (and we love it :-) of the 'oldschool'
numerically
indexed array and what is commonly known as a hash (or arraymap) - 
you can mix
numeric and associative indexes freely (that might seem odd and/or 
bad when

coming
from another language but it really is fantastic once you get your 
head round

it).

  


values like with array_push in arrays as bellow?

$colors = array(
 'red' = '#ff',
 'green' = 'X00ff00',
 'blue' = '#ff'
  );




sure:

$colors['grey'] = '#dedede';

the position of the 'inserted' (actually appended) is often not
important - if it is there are plenty of functions that allow you to
manipulate
arrays in more a complex fashion e.g. array_splice(). and all sorts 
of sorting

functions are also available e.g. asort().

check out the vast number of array related function and introductory 
texts

here:

http://php.net/array
http://php.net/manual/language.types.array.php

  


Tanks in advance // Jonas





  



 





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



Re: [PHP] array_push in array maps

2006-05-03 Thread John Wells

On 5/3/06, Jochem Maas [EMAIL PROTECTED] 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