Solved

how can I modify foreach to iterate the values of an array or arrays

Posted on 2014-04-29
2
248 Views
Last Modified: 2014-04-29
<?php
  $configData= array("PersonModule" => array( 'person'=>'bob' ),"FtpModule"    => array( 'host' =>'example.com','user'  =>'anon' ));
  foreach ($configData as $name=>$value){
    echo '<br>name: '.$name.' value: '.$value;
  }
  

Open in new window


Notice: Array to string conversion in C:\Users\Acer\Documents\NuSphere PhpED\Projects\noname308.php on line 4

name: PersonModule value: Array
Notice: Array to string conversion in C:\Users\Acer\Documents\NuSphere PhpED\Projects\noname308.php on line 4

name: FtpModule value: Array


how can I modify foreach to iterate the values of an array or arrays
0
Comment
Question by:rgb192
2 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 40031107
You would need to set up a secondary foreach to handle the second array:

<?php
  $configData= array("PersonModule" => array( 'person'=>'bob' ),"FtpModule"    => array( 'host' =>'example.com','user'  =>'anon' ));
  foreach ($configData as $name=>$array){
      foreach ($array as $key => $value) {
    echo '<br>name: '.$name.' value: '.$value;  // or echo '<br>name: ' . $name.' key: '.$key.' value: '.$value;
      }
  }
   

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 40031151
thanks for foreach array
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now