Get the key of a JSON in PHP? (Not the value but the key)

0

I have a JSON Object that sent it from android to PHP it's similar to this

{"1":"insert 1", "2":"insert 2", "3":"insert 3" } 

the number is the id of the record and the insert is a sql instruction that is executed to save values in a BASE now I need to return my android application in ID of each sentence executed. the sentence is executed well but I do not know how to put into an array those IDs that are the key of each JSON here the code that I use in the server:

foreach ($capturas as $cap ) {  
    foreach ($cap as $key ) {
        $result = pg_query($dbconn,$key) or die("falla");
    }   
    $insertedArray[]=$cap;  
}

It is in the insertedArray where I need to save IDs

    
asked by Igmer Rodriguez 17.09.2018 в 18:52
source

1 answer

2

Try this:

foreach($capturas as $cap) {
    foreach($cap as $key => $val) {
        echo $key . ': ' . $val;
        echo '<br>';
    }
}

In $ key you will get the names of the keys and in the $ val you will get the values

    
answered by 17.09.2018 / 19:05
source