TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-05-2008, 04:16 AM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default 2-d arrays -- issues of printing and deleting

I have an array of arrays, like so:

$arr = array(array('blue','green','yellow'),
array('fall','winter','summer'),
array('Ford','GMC','Toyota')
)


I want to print_r(), say, only the seasons and the cars, how would I do this?

Also, how could I delete one of the arrays?

Thanks for your help!

Dave
Dave is offline  
Reply With Quote
Old 06-05-2008, 07:43 AM   #2 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

well,
PHP Code:
echo('<pre>');
print_r($arr[1]); //Seasons
print_r($arr[2]); //Cars
echo('</pre>'); 
To delete one, it would probaly require you to do some loop or stuff like that..
SpYkE112 is offline  
Reply With Quote
The Following User Says Thank You to SpYkE112 For This Useful Post:
Dave (06-05-2008)
Old 06-05-2008, 11:44 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

To delete a part of the array use unset:

php Code:
unset($arr[1]);
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Dave (06-05-2008)
Old 06-05-2008, 11:45 AM   #4 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

php.net/unset

PHP Code:
unset($arr[1]); 
The only issue is if I'm not mistaken is, the array will persist with the current numerical order - meaning it'll be something like this

PHP Code:
$arr[0]
$arr[2
you can use a combination of array_splice/array_merge to properly delete array elements and have them be in correct numerical order.
Enfernikus is offline  
Reply With Quote
The Following User Says Thank You to Enfernikus For This Useful Post:
Dave (06-05-2008)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:30 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design