Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<pre>Array
$test = (
    [0] => Array
        (
            [name] => noofApplicationsused
            [value] => q1a1
        )

    [1] => Array
        (
            [name] => noofApplicationsused
            [value] => q1a2
        )

    [2] => Array
        (
            [name] => noofApplicationsused
            [value] => q1a3
        )

    [3] => Array
        (
            [name] => visibilityintoSODviolations
            [value] => q2a1
        )

    [4] => Array
        (
            [name] => currentlyhaveoutoftheboxorcustomrulesets
            [value] => q3a1
        )

    [5] => Array
        (
            [name] => rAwhataccessintheriskisbeingexecutedbytheuser
            [value] => q4a1
        )

    [6] => Array
        (
            [name] => mitigatingcontrolsdefinedforallapplicablerisks
            [value] => q5a1
        )

    [7] => Array
        (
            [name] => howregulatorycontrolsareenforced
            [value] => q8a1
        )

    [8] => Array
        (
            [name] => processformanaginguserrequests
            [value] => q9a1
        )

    [9] => Array
        (
            [name] => reviewyourlicensesbyapplication
            [value] => q10a1
        )

    [10] => Array
        (
            [name] => formid
            [value] => 1809
        )

    [11] => Array
        (
            [name] => munchkinId
            [value] => 507-NMC-378
        )

)

I want to run the loop and get the name and value
New to PHP so not able to figure out

What I have tried:

foreach($test as $tst){
      print_r ($tst[0][name]);
  }
Posted
Updated 19-May-22 6:10am
Comments
Richard MacCutchan 19-May-22 6:00am    
What happens when you run that code?

1 solution

Hello !

you want to fetch a 2 dimensional array with php

as index ( 1 ,2 ,3 ,4 ,5 ) just require incrementation, literals like [name, value] needs to be enclose for a call :
PHP
echo $output[0]['name'] ;



belonging to the php.ini quotes apply , maybe
PHP
echo $output[0]["name"] ;


check and set php.ini to fix your favorite one.

official resource : PHP: Hypertext Preprocessor[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900