D
D
dizee2017-04-29 22:38:04
Arrays
dizee, 2017-04-29 22:38:04

Forming 1 array in a foreach loop?

Help form an array of the form:

Array
(
    [0] => 11;22
    [1] => 11;22
    [2] => 22;22
)

From the foreach loop where I get the required values
foreach ($arrrr as $element) {
    if ($element->Brand == 'AAA' || $element->Brand == 'BBB') {
          	$element->Name;
          	$element->Brand;
          	$element->Price;
    }

The new array needs $element->Name; $element-> Brand; separated by commas
As a result, you need:
Array
(
    [0] => $element->Name;$element->Brand;$element->Price;
    [1] => $element->Name;$element->Brand;$element->Price;
    [2] => $element->Name;$element->Brand;$element->Price;
)

Drank coffee, got a solution:
$newarr = [];
foreach ($arrrr as $element) {
    if ($element->Brand == 'AAA' || $element->Brand == 'BBB') {
          	$newarr[] = $element->One . ";" . $element->Ones;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question