Re: [PHP] Check for Associative Array

2002-07-18 Thread Steve Edberg

At 12:57 PM -0400 7/18/02, Henning Sittler wrote:
>What's the best way to check for an Associative Array?  There is no
>is_assoc() or similiar function listed in the manual (I don't think anyway).


No, because AFAIK all PHP arrays are associative; there is no 
distinction between arrays & hashes as in Perl.


>I'm using mysql_fetch_array() and I want to foreach only the assoc. part of
>the array without using mysql_fetch_assoc():
>
>foreach ($arr as $key=>$value) {
>   echo "$key:$value";
>}


If you really don't want to use mysql_fetch_assoc(), you can use the 
second parameter of mysql_fetch_array():

$arr = mysql_fetch_array($ResultHandle, MYSQL_FETCH_ASSOC);

This functions exactly like mysql_fetch_assoc(), and is available in 
PHP >= 3.0.7.

See

http://www.php.net/manual/en/function.mysql-fetch-array.php

for more info.


>But of course it show both the indexed array and the assoc array contents.
>Is there an existing function to check this, or should I do one of these
>things inside the foreach loop:
>
>A) set $last=value and just check if $value = $lastval
>
>B) check if the $key is just a number or just a string
>
>C) $key += 1


Lastly, you _could_ just step through the array using each() in a 
loop, and use only every OTHER array entry...but this is really funky 
and you shouldn't do it this way anymore.

-steve


>
>?? Thanks,
>
>
>Henning Sittler
>www.inscriber.com
>


-- 
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| The end to politics as usual:  |
| The Monster Raving Loony Party (http://www.omrlp.com/) |
++

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




Re: [PHP] Check for Associative Array

2002-07-18 Thread Kevin Stone

foreach ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//...
}

Is this what you need?
http://www.php.net/manual/en/function.mysql-fetch-array.php

-Kevin

- Original Message -
From: "Henning Sittler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 18, 2002 10:57 AM
Subject: [PHP] Check for Associative Array


> What's the best way to check for an Associative Array?  There is no
> is_assoc() or similiar function listed in the manual (I don't think
anyway).
>
> I'm using mysql_fetch_array() and I want to foreach only the assoc. part
of
> the array without using mysql_fetch_assoc():
>
> foreach ($arr as $key=>$value) {
> echo "$key:$value";
> }
>
> But of course it show both the indexed array and the assoc array contents.
> Is there an existing function to check this, or should I do one of these
> things inside the foreach loop:
>
> A) set $last=value and just check if $value = $lastval
>
> B) check if the $key is just a number or just a string
>
> C) $key += 1
>
>
> ?? Thanks,
>
>
> Henning Sittler
> www.inscriber.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




Re: [PHP] Check for Associative Array

2002-07-18 Thread Martin Clifford

Oh well.  And HTH means "Hope to Help".

> For some unknown reason the OP specifically does not want to use 
> mysql_fetch_assoc()!

Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/



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




Re: [PHP] Check for Associative Array

2002-07-18 Thread Jason Wong

On Friday 19 July 2002 01:19, Martin Clifford wrote:
> Try this:
>
> while($row = mysql_fetch_assoc($result)) {
> // code here
> }
>
> This way, the resulting array will ONLY be associative.

For some unknown reason the OP specifically does not want to use 
mysql_fetch_assoc()!

> I'm using mysql_fetch_array() and I want to foreach only the assoc. part of
> the array without using mysql_fetch_assoc():


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
People are beginning to notice you.  Try dressing before you leave the house.
*/


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




RE: [PHP] Check for Associative Array

2002-07-18 Thread Henning Sittler

Ya, except I want the whole array to exist (index and assoc. array), not
just the assoc. array.  So, for the time being, I'll just do this:

foreach ($arr as $key=>$value) { 
  if ( !is_int($key) ) { echo "$key:$value"; }
}

What is HTH ??

Henning Sittler
www.inscriber.com



Try this:

while($row = mysql_fetch_assoc($result)) {
// code here
}

This way, the resulting array will ONLY be associative.

HTH!

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




Re: [PHP] Check for Associative Array

2002-07-18 Thread Martin Clifford

Try this:

while($row = mysql_fetch_assoc($result)) {
// code here
}

This way, the resulting array will ONLY be associative.

HTH!

Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/


>>> Henning Sittler <[EMAIL PROTECTED]> 07/18/02 12:57PM >>>
What's the best way to check for an Associative Array?  There is no
is_assoc() or similiar function listed in the manual (I don't think anyway).

I'm using mysql_fetch_array() and I want to foreach only the assoc. part of
the array without using mysql_fetch_assoc():

foreach ($arr as $key=>$value) { 
echo "$key:$value";
}

But of course it show both the indexed array and the assoc array contents.
Is there an existing function to check this, or should I do one of these
things inside the foreach loop:

A) set $last=value and just check if $value = $lastval

B) check if the $key is just a number or just a string

C) $key += 1


?? Thanks,


Henning Sittler
www.inscriber.com 

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



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