F
F
Formula_12018-02-12 06:45:07
PHP
Formula_1, 2018-02-12 06:45:07

How to find an element in an array?

Tell me, please, there are two arrays:
The main array, where the values ​​are needed from:

[0] => Подключения
[1] => Эксплуатация
[2] => Эксплуатация
[3] => Подключения
[4] => Эксплуатация
[5] => Подключения
[6] => Подключения
[7] => Подключения
и т.д.

The second array where the keys are stored
[0] => 0
[1] => 3
[2] => 5
[3] => 6
[4] => 7
[5] => 8
[6] => 9
[7] => 10
и т.д.

How to find the elements in the first array by the keys that are stored in the second one? Maybe swap the key-value in the second array and apply array_intersect_key?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2018-02-12
@Formula_1

Searching in an array using an array of keys?

S
Stalker_RED, 2018-02-12
@Stalker_RED

We look at the list Functions for working with arrays
It looks like this one will do:

$a = [
0 => 'Подключения',
1 => 'Эксплуатация',
2 => 'Эксплуатация',
3 => 'Подключения',
4 => 'Эксплуатация',
5 => 'Подключения',
6 => 'Подключения',
7 => 'Подключения',
];
 
$b = [
0 => 0,
1 => 3,
2 => 5,
3 => 6,
4 => 7,
5 => 8,
6 => 9,
7 => 10,
];
 
$c = array_combine($b, $a);
 
echo $c[7]; // Эксплуатация

https://ideone.com/refyj1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question