Re: [PHP] two dimensional array or two arrays?

2001-08-28 Thread Philip Olson


Your $categoryarry is a 2d array, try :

  print_r($categoryarry);

But, I think you want to do :

  $categories = array('Sasheen','Tom','Fred');

Now, if you do this :

  while(list($key,$value) = each($categories)) {
  
print "$key : $value\n";
  }

You'll get :

  0 : Sasheen
  1 : Tom
  2 : Fred

Could also define your array like so :

  $categories = array('a' => 'foo', 'b' => 'bar');

Which, if run through our loop above, will give us :

  a : foo
  b : bar

See?  Play with it a bit, it'll start to make more and more sense.

Regards,
Philip


On Tue, 28 Aug 2001, Tom Beidler wrote:

> I have some code I use to create pulldown menus. It's as follows;
> 
> $categoryarry = array("","1","2","3","4","5");
> while (list($key,$value) = each($categoryarry)) {
>   if ($value == $srch_cat) {
> $cat_option .= "$value\n";
>   } else {
> $cat_option .= "$value\n";
>   }
> }
> 
> It works fine when the pulldown value and displayed text are the same, ie.
> 
> John
> 
> But now I would like to change so the value is different then what's
> displayed in the menu, ie.
> 
> John
> 
> I've never used two dimensional arrays but I thought it might be what I need
> to look into. Or should I have to arrays and use one for the value and the
> other for the item displayed in the pulldown menu.
> 
> Any help appreciated.
> 
> Thanks,
> Tom
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] two dimensional array or two arrays?

2001-08-28 Thread Anton Stroganov

this should do it for you.

$categoryarry = array(array("","none"),array("1","John"),array("2","Jim"));
foreach($categoryarray as $value) {
  if($value[0] == $srch_cat) {
$cat_option .= "$value[1]\n";
  } else {
$cat_option .= "$value[1]\n";
  }
}

- Original Message -
From: Tom Beidler <[EMAIL PROTECTED]>
To: php list <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2001 12:23
Subject: [PHP] two dimensional array or two arrays?


> I have some code I use to create pulldown menus. It's as follows;
>
> $categoryarry = array("","1","2","3","4","5");
> while (list($key,$value) = each($categoryarry)) {
>   if ($value == $srch_cat) {
> $cat_option .= "$value\n";
>   } else {
> $cat_option .= "$value\n";
>   }
> }
>
> It works fine when the pulldown value and displayed text are the same, ie.
>
> John
>
> But now I would like to change so the value is different then what's
> displayed in the menu, ie.
>
> John
>
> I've never used two dimensional arrays but I thought it might be what I
need
> to look into. Or should I have to arrays and use one for the value and the
> other for the item displayed in the pulldown menu.
>
> Any help appreciated.
>
> Thanks,
> Tom
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] two dimensional array or two arrays?

2001-08-28 Thread Tom Beidler

I have some code I use to create pulldown menus. It's as follows;

$categoryarry = array("","1","2","3","4","5");
while (list($key,$value) = each($categoryarry)) {
  if ($value == $srch_cat) {
$cat_option .= "$value\n";
  } else {
$cat_option .= "$value\n";
  }
}

It works fine when the pulldown value and displayed text are the same, ie.

John

But now I would like to change so the value is different then what's
displayed in the menu, ie.

John

I've never used two dimensional arrays but I thought it might be what I need
to look into. Or should I have to arrays and use one for the value and the
other for the item displayed in the pulldown menu.

Any help appreciated.

Thanks,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]