Manipulating records from a php array

Asked

Viewed 198 times

0

I have a query in the database that returns the records in an array, I would like to know how to manipulate these records, take them from the array.

Code

$array = MinPDO::consult("intro", NULL, "id > 1", "id-", "3", "%e%");

var_dump($array);

Records

array(3) { [0]=> array(3) { ["id"]=> int(3) ["param1"]=> string(5) "ele01" ["param2"]=> string(6) "param2" } [1]=> array(3) { ["id"]=> int(2) ["param1"]=> string(5) "ele01" ["param2"]=> string(6) "param2" } [2]=> array(3) { ["id"]=> int(1) ["param1"]=> string(5) "ele01" ["param2"]=> string(6) "param2" } } 
  • 1

    Where you want to manipulate in the view or in php code itself?

  • To access some value you can do $array[0]['param1']

  • In the view and in the code itself too.

1 answer

1


You can use the foreach for this follows below an example

foreach($array as $info) {
    echo $info['id']." - ".$info['param2']."<br/>";
}

It has the go also put the foreach better

for($i = 0; $i < count($array); $i++) {
    echo $array[$i]['id']." - ".$array[$i]['param2']."<br/>";
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.