B
B
BoriHagen2020-04-24 20:55:45
PHP
BoriHagen, 2020-04-24 20:55:45

How to display an array in php in key value format?

There is an array generated by the mysqli_fetch_all( ) function. Namely, the data derived from the database table:

$stock_data = mysqli_fetch_all(mysqli_query($connection, "SELECT * FROM `stock`"));
foreach ($stock_data as $key => $value) {
    echo "{$key} => {$value} ";
}


I'm trying to loop through it and get an array in the format Array[ "field name" => "value"], Array[ "field name" => "value"], Array[ "field name" => "value"]. But nothing works. Kindly tell me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2020-04-24
@BoriHagen

1. You first need to understand in what form the data comes from mysqli_fetch_all, and then write a loop for processing.
2. You will have to process each entry in a loop

V
Vladislav, 2020-04-24
@cr1gger

var_dump($array);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question