Strip numerical indices from array

This is a discussion on Strip numerical indices from array within the PHP General forums, part of the PHP Programming Forums category; PHP General list, I've got an associative array that also includes a numerical index. The numerical index was automatically ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-13-2007
Dave M G
 
Posts: n/a
Default Strip numerical indices from array

PHP General list,

I've got an associative array that also includes a numerical index. The
numerical index was automatically generated from the mysql_fetch_array
command, so it the values are the duplicates of the associative key names.

Is there a way to simply strip off the numerical index, leaving only the
associative key names?

--
Dave M G
Reply With Quote
  #2 (permalink)  
Old 08-13-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Strip numerical indices from array

There is, but you want to be using mysql_fetch_assoc() instead which gives you
just the keyed indexes in the first place.

Or, better yet, use mysqli_ or PDO which offer better security than mysql_ if
you're running PHP 5 (which you are, right? <g>)

On Sunday 12 August 2007, Dave M G wrote:
> PHP General list,
>
> I've got an associative array that also includes a numerical index. The
> numerical index was automatically generated from the mysql_fetch_array
> command, so it the values are the duplicates of the associative key names.
>
> Is there a way to simply strip off the numerical index, leaving only the
> associative key names?
>
> --
> Dave M G



--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #3 (permalink)  
Old 08-13-2007
Dave M G
 
Posts: n/a
Default Re: [PHP] Strip numerical indices from array [SOLVED]

Larry,

Thank you for responding.
> ... you want to be using mysql_fetch_assoc() instead...

Thank you, that helps me achieve what I need.

> Or, better yet, use mysqli_ ... if
> you're running PHP 5 (which you are, right?

Yes, I am running PHP 5. However, this mysqli usage is clearly not as
simple as replacing every instance of mysql_ with mysqli_.

I will look into it further and see if I can migrate to using mysqli_
somehow.

Thank you for the advice.

--
Dave M G
Reply With Quote
  #4 (permalink)  
Old 08-13-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Strip numerical indices from array [SOLVED]

On Monday 13 August 2007, Dave M G wrote:
> Larry,
>
> Thank you for responding.
>
> > ... you want to be using mysql_fetch_assoc() instead...

>
> Thank you, that helps me achieve what I need.
>
> > Or, better yet, use mysqli_ ... if
> > you're running PHP 5 (which you are, right?

>
> Yes, I am running PHP 5. However, this mysqli usage is clearly not as
> simple as replacing every instance of mysql_ with mysqli_.
>
> I will look into it further and see if I can migrate to using mysqli_
> somehow.


True, it's not. And actually depending on your use case (shared server,
dedicated, etc.) PDO may be a better target since PDO is part of a default
PHP 5 install these days but I don't believe mysqli is. I'm just pointing
out that there are better database drivers than mysql_, especially with
regards to security. (Prepared statements FTW!)

--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:11 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0