Solved

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

Posted on 2014-04-29
2
238 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 13
Why does this login script not work on a live server? 19 41
php documentation 4 22
two tables one button 11 20
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …

747 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

13 Experts available now in Live!

Get 1:1 Help Now