D
D
Dmitry2021-08-23 15:37:01
PHP
Dmitry, 2021-08-23 15:37:01

How to output php array correctly?

There is an array.
There is an index.php file, into which the data from the array is pulled.
How can I make it so that somewhere in this file I specify 1 time a key, such as "stul", so that when I call it, write predmet. Thus, if there are a lot of index.php files and in the file itself a call from an array is used a lot, I would indicate this key at the beginning of the file and that's it.
612395bb418e2164881312.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-08-23
@se_demon

Instead of separate arrays for each item, create a single array:

$items = [
    'school_table' => [
        'name' => 'School Table',
        'price' => 100
    ],
    'school_chair' => [
        'name' => 'School Chair',
        'price' => 50
    ]
];

$item = $items[ 'school_table'];

echo $item['name'] . ' for ' . $item['price'] . ' money';

Share PHP code online

I
inFureal, 2021-08-23
@inFureal

// massive.php
return [
"stul" => []
]

//index.php
$items = require("massive.php"); // items массив который вернул massive

// ниже где хочешь 
$items["stul"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question