P
P
PeteDoherty2019-07-10 23:00:56
PHP
PeteDoherty, 2019-07-10 23:00:56

How to iterate over two arrays at the same time?

You need to loop through the array to display the desired values.

$result = [
    "CARS" => [
        "[email protected]" => ["name" => "Tesla Model X", "year" => "2012"], 
        "[email protected]" => ["name" => "Ford Mustang","year" => "1965"],
        "[email protected]" => ["name" => "Camaro SS","year" => "1961"],
    ],
    "BOOKS" => [
        ["bookName" => "Tesla Rules", "authorEmail" => "[email protected]"],
        ["bookName" => "Ford Mustang Rules", "authorEmail" => "[email protected]"],
        ["bookName" => "Camaro SS rules", "authorEmail" => "[email protected]"],
    ],
];


Explain how it is possible to iterate over an array here in such a way as to extract the following from it: A

book ... was written for a car ... in ... a year, can be ordered by e-mail ...

them?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-07-10
@PeteDoherty

The array_map function can operate on more than one array:

echo implode('<br>', array_map(function($n, $i) use(&$result) {
  return
    "Книгу ".$result['BOOKS'][$i]['bookName'].
    " написали для машины ".$n['name']." в ".$n['year'].
    " году, можно заказать по электронной почте ".$result['BOOKS'][$i]['authorEmail'];
}, $result['CARS'], array_keys($result['BOOKS'])));

N
nozzy, 2017-10-04
@Vladimir_Pridannikov

Strange logic, I would first change the query to:
So try:

c.execute('SELECT tgid FROM accounts where tgid =?', message.from_user.id)
temp =  c.fetchone()
if temp is None:
*Если нет в БД*
else:
*если есть в БД*

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question