Join two array in php

0

Good morning guys, a quick question. I need to merge two array of a query as follows:

$tamanhos = array('p', 'm', 'g');
$valor_item = array('10', '20', '30');

where "p" has to be equal to 10, m = 20, g = 30

This can make a foreach that binds the two arrays to display the size with the value of each item.

I think this would give you a better understanding of what I need.

Thank you and waiting.

    
asked by anonymous 15.09.2018 / 16:36

1 answer

2

First of all check the syntax of arrays.

$tamanhos = array('p', 'm', 'g');
$valor = array('10', '20', '30');
$result = array_combine($tamanhos, $valor);

print_r($result);

running on ideone

Result:

Array
(
    [p] => 10
    [m] => 20
    [g] => 30
)

a rray_combine - Create an array using an array to keys and another one for values

    
15.09.2018 / 17:04