473,748 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using foreach loop to get values of a multi-dimensional arrays

khalidbaloch
61 New Member
hi every one, how are you folf , hope fine

dear Friends i want to get values of multi-dimensional arrays using foreach loop and after that print out the html using an other while loop ,
i tried alot but did not successed accutly i want to create an yahoo api websearch application i got a sample from developer.yahoo .com for this purpose ,this sample uses unserialize/serialize php
here is the code exapmle


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Parsing Yahoo! REST Web Service results using
  3. // unserialize. PHP4/PHP5
  4. // Author: Jason Levitt
  5. // February 1, 2006
  6.  
  7. // output=php means that the request will return serialized PHP
  8. $request =  'http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=dboyzclan&query=php sample&results=4&output=php';
  9.  
  10. $response = file_get_contents($request);
  11.  
  12. if ($response === false) {
  13.     die('Request failed');
  14. }
  15.  
  16. $phpobj = unserialize($response);
  17.  
  18. echo '<pre>';
  19. //this will print the arrays
  20. print_r($phpobj);
  21. echo '</pre>';
  22. ?>
allthogh this will show the result
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //show result no 1
  4. //this will show the url of result 1
  5. echo $phpobj['ResultSet']['Result']['0']['Url'];
  6. echo '<br>';
  7. //this will show the title of result no 1
  8. echo $phpobj['ResultSet']['Result']['0']['Title'];
  9. echo '<br>';
  10.  
  11. //this will show the Summary of result no 1
  12. echo $phpobj['ResultSet']['Result']['0']['Summry'];
  13. echo '<br>';
  14.  
  15. //Result no 2
  16.  
  17.  
  18. //this will show the url of result 2
  19. echo $phpobj['ResultSet']['Result']['1']['Url'];
  20. echo '<br>';
  21. //this will show the title of result no 2
  22. echo $phpobj['ResultSet']['Result']['1']['Title'];
  23. echo '<br>';
  24.  
  25. //this will show the Summary of result no 2
  26. echo $phpobj['ResultSet']['Result']['1']['Summry'];
  27. echo '<br>';?>
and there numberiuos thing in that array which can be print by print_r(); function

but what i want to do increament dynamically the third value of array using a loop , but how to do that any help would be highly appriciated
Jan 8 '07 #1
1 4337
ronverdonk
4,258 Recognized Expert Specialist
I do not really understand what you are asking for, so I'll guess: you want to list the url, title and summary entries of this array? I'll show a cde snippet that does that, but is this what you mean and want?
[php]<?php
// ----------- Setup ther test array
$phpobj=array() ;
$phpobj['ResultSet']['Result']['0']['Url'] = 'URL no 0';
$phpobj['ResultSet']['Result']['0']['Title']='TITLE no 0';
$phpobj['ResultSet']['Result']['0']['Summry']='SUMMARY no 0';
$phpobj['ResultSet']['Result']['1']['Url'] = 'URL no 1';
$phpobj['ResultSet']['Result']['1']['Title']='TITLE no 1';
$phpobj['ResultSet']['Result']['1']['Summry']='SUMMARY no 1';
$phpobj['ResultSet']['Result']['2']['Url'] = 'URL no 2';
$phpobj['ResultSet']['Result']['2']['Title']='TITLE no 2';
$phpobj['ResultSet']['Result']['2']['Summry']='SUMMARY no 2';

// Print out the entries
foreach ($phpobj as $resultset) {
foreach ($resultset as $result) {
foreach ($result as $entry) {
echo "URL={$entr y['Url']}<br>";
echo "TIT={$entr y['Title']}<br>";
echo "SUM={$entr y['Summry']}<br>";
}
}
}

?>[/php]
Ronald :cool:
Jan 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
12416
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality provided by Informix. This is the problem: the execution of the translated SQL leaves the rows in the temp table correctly but raises error SQL0480N. It's very simple to try it: ------------
7
4378
by: Alvin Bruney | last post by:
Error: Collection was modified; enumeration operation may not execute. I've dodged this issue for a while now with workarounds but now i want to stand up and fight. I don't want to run away from it anymore. How do I get around tampering with a collection within a loop and keep iterating. Here is my code: //Threadwork.Getlist returns a hash table
9
6172
by: Art | last post by:
Hello, Here is a fragment of my code, which fails and I don't know why. --------------------------------- XmlDocument doc = new XmlDocument(); doc.Load(@"C:\mydoc.xml"); foreach (XmlNode objNode in doc.SelectNodes("author")) { System.WriteLine(objNode.Value.ToString()); } ---------------------------------------------------------------
104
7189
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars foeach(Color c in Red..Blue) { } // using enums It should work with all integral datatypes. Maybe we can step a bit further: foeach(int i in 1..10, 30..100) { } // from 1 to 10 and 30 to hundred
3
2747
by: pbali | last post by:
Hi, I am using PHP 5.1 and MySQL. I have a result set obtained by executing PDO:: query. I want to create an XML file by using this result set. The XML file will contain column names as XML node name and column values as node values. $orders = $db->query($sql); if (!empty($orders)) {
0
1406
by: koonda | last post by:
Hi guys, I posted a message before and I got some help from the forum. I have a database in SQL Server and I wanted to create a web interface in C#. I had 4 Listbox controls and a Textbox and two buttons for this. What I want to do is to select values from 4 Listbox controls and input some text in the textbox i.e year to display information on another page including all the information from $ listboxes too. I have no idea how to program this...
3
33369
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current code is here: foreach ( string propertyName in ht.Keys ) { this.setProperty( propertyName, ht );
29
4251
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to a temp array and delete afterwards if necessary but since I'm actually working in a nested situation this could get a little messy. I guess I could set there values to null and remove them afterwards? Thanks, Jon
9
5616
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return String.Format("'{0}'", value) End Function Basically, I just want to surround each value with single quotes. However, I am having trouble getting this to work using the System.Array.ForEach method. This may be partially because I am not very...
6
2944
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8245
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.