1

I have the following array stored in $members

array(3) { 
[0]=> array(2) { 
    ["index"]=> string(1) "1" 
    ["routePartitionName"]=> string(20) "US-555-foop-GWRoutes" } 
[1]=> array(2) { 
    ["index"]=> string(1) "2" 
    ["routePartitionName"]=> string(27) "Cluster DN Presence Allowed" } 
[2]=> array(2) { 
    ["index"]=> string(1) "3" 
    ["routePartitionName"]=> string(26) "Cluster DN Presence Denied" } 
}

I'm trying to embed this into another array during a foreach loop. However it seems to evaluate the $members variable as text.

$programTags[] = array(
    "name"=>"$cssname",
    "description"=>"$cssdescription",
    "members"=>"$members");

How can I expand the variable thus creating a multidimensional array?

2 Answers 2

1
Remove the quotes from $members variable, it convert it into string.
$programTags[] = array(
    "name"=>"$cssname",
    "description"=>"$cssdescription",
    "members"=>$members);
Sign up to request clarification or add additional context in comments.

1 Comment

Worked exactly like I wanted. Thank you.
0

using nested foreach

foreach($members as $array)
{
    //$array is array variable .

     foreach($array as $values)
     {
        //your code here
     }
}

exapmple:

$member = array(3) { 
               [0]=> array(2) { 
                         ["index"]=> string(1) "1" 
                         ["routePartitionName"]=> string(20) "US-555-foop-GWRoutes" } 
               [1]=> array(2) { 
                         ["index"]=> string(1) "2" 
                         ["routePartitionName"]=> string(27) "Cluster DN Presence Allowed" } 
               [2]=> array(2) { 
                        ["index"]=> string(1) "3" 
                        ["routePartitionName"]=> string(26) "Cluster DN Presence Denied" } 
           }

applaying foreach then,

$array = array(2) { 
                         ["index"]=> string(1) "1" 
                         ["routePartitionName"]=> string(20) "US-555-foop-GWRoutes" 
          }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.