F
F
feniksdv2018-04-02 20:23:25
PHP
feniksdv, 2018-04-02 20:23:25

How to search through an array, do you need to search not the whole value, but only a part?

There is an array

Array
( 
    [0] => 
    [1] => ID - 50 Наличие интернет - Да
    [2] => ID - 50 Процент - 20%
    [3] => ID - 50  наличных -  2,9%
    [4] => ID - 50 Минимальный размер - 5%
    [5] => ID - 50 Наличие эксклюзивных предложений  - да
    [6] => ID - 50 период - 55
    [7] => ID - 60  других - 2,9
    [8] => ID - 60 Наличие - да
    [9] => ID - 60  наличных  - 2.9
    [10] => ID - 60 Минимальный размер - 600
    [11] => ID - 60 Наличие скидок и предложений - да
    [12] => ID - 60 период - 55
    [13] =>

I need to do the following, if 50 is encountered, display the title (let's say the conditions) + all the lines where 50 is.
Already broke his head help implement.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tigra, 2018-04-02
@feniksdv

$yourArray= [
   '50 Наличие интернет - Да',
   'ID - 50 Процент - 20%',
   'ID - 50  наличных -  2,9%',
   'ID - 50 Минимальный размер - 5%',
   'ID - 50 Наличие эксклюзивных предложений  - да',
   'ID - 50 период - 55',
   'ID - 60  других - 2,9',
   'ID - 60 Наличие - да',
   'ID - 60  наличных  - 2.9',
   'ID - 60 Минимальный размер - 600',
   'ID - 60 Наличие скидок и предложений - да',
   'ID - 60 период - 55',
];
    
$needle = '50';

$matches = array_filter($yourArray, function ($haystack) use ($needle) {
    return(strpos($haystack, $needle));
});

print_r($matches);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question