The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 02:40:38 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: foreach and array item names  (Read 1249 times)
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« on: October 02, 2009, 06:28:55 AM »

Ok, I have this:
Code:
$lovely_array = array('first_name' => 'perki', 'last_name' => 'set');
What if I want to get both item content and item name like this:
first_name is perki and last_name is set.

How can I do this?

Now my multicurl class returns array where downloaded content is in array and array item name is url. So I need to match content with url it was downloaded from.
« Last Edit: October 02, 2009, 06:30:45 AM by kurdt » Logged

I met god and he had nothing to say to me.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #1 on: October 02, 2009, 06:34:30 AM »

Found it. Now I know why foreach loop has that third param Wink

So to everybody who have wondered this thing, answer is really easy.

You can print the value and the key with this:
Code:
foreach ($array as $key => $value) {
echo $key." is ".$value."\n";
}
Logged

I met god and he had nothing to say to me.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!