0

I want to pass more parameters in this function:

$option1=$res['attributes'][0]['option'];
$option2=$res['attributes'][1]['option'];
$row['variations'] = array_map(function($var) {
return ['id' => $var];}
,$row['variations']);

Now, I am able only to pass $var, and I want to have

['id' => $var,
 'option1'=>$option1,
 'option2'=>$option2]

This is my response now:

 0 => array:1 [▼
    "id" => 3095
  ]
  1 => array:1 [▼
    "id" => 3096
  ]

And I need something like

 0 => array:1 [▼
    "id" => 3095,
    "option1"=>"Blue",
    "option2"=>"M"

  ]
 
2
  • 1
    try array_map(function() use($var,$option1,$option2){ Commented Jan 14, 2023 at 16:48
  • 1
    You can find more information and example from docs for your queston php.net/manual/en/function.array-map.php Commented Jan 14, 2023 at 16:48

1 Answer 1

0

You can find more information and example from docs php.net/manual/en/function.array-map.php

$option1=$res['attributes'][0]['option'];
$option2=$res['attributes'][1]['option'];
$row['variations'] = array_map(null, $option1,$option2)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.