1
Given the table marcas
of the database teste_db
(for example)
| id | marca |
| 1 | mercedes|
| 2 | audi |
| 3 | fiat |
| 4 | alfa |
| ...| ... |
|573 | ferrari |
|574 | bentley |
and given an array with n
numerical arguments such as:
$arr = array('3','23','127','574')
and assuming that the array will always contain numerical arguments that can be found in the column id
of this table, I would like to include in the array, for each argument of this, the value marca
whose id
table has the same array value, and the result would be:
$arr = array("3"=>"fiat", "23"=>"rover", "127"=>"tata", "574"=>"bentley");
What code would be required for this task? PHP and mysqli.
And what exactly would it be
$k
and$v
? You can [Edit] the question and add how the desired result would look?– Woss
The
$k
and the$v
are the keys and values, respectively of an array wherearray ( $k => $v)
– Goncalorsr
Of which array? You’re confused. What is the relationship of array
$arr
and the database table? What exactly do you want to do? Remember to add to the question the example of the expected result.– Woss
If the procedure is done, as I imagine, using
mysqli_query
, is obviously implicit the connection to the database. My question will be after this step.– Goncalorsr