D
D
Dmitry2017-05-06 12:32:08
PHP
Dmitry, 2017-05-06 12:32:08

Outputting an array element with a condition on another array element?

There is this array $services:

Array
(
    [0] => Array
        (
            [id_room] => 1
            [id_service] => 1
            [service_name] => Обслуживание
        )

    [1] => Array
        (
            [id_room] => 2
            [id_service] => 1
            [service_name] => Обслуживание
        )

    [2] => Array
        (
            [id_room] => 1
            [id_service] => 2
            [service_name] => Развлечения
        )
)

You need to output service_nameif id_room, for example, is equal to 1.
I've tried outputting through a loop, checking like this:
for ($i = 0; $i < 3; $i++){
    if($services[$i]['id_room'] = 1){
        echo $services[$i]['service_name'];
    }
};

But it seems to me that this option will not work (it does not work), but I don’t really understand how to do it otherwise. At least tell me in which direction to google :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-05-06
@letehaha

Of course it won't work.

$services[$i]['id_room'] == 1
//                       /\ ТУТ ЗНАК сравнения(==), а у вас знак присвоения(=).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question