[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-04-29
2
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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