Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing array shared values at once

Tags:

arrays

php

Maybe this isn't possible, I've never seen it myself, but thought I'd ask. If this is my array,

$myarr = array(
   'red'   => 7, 
   'green' => 7,
   'blue'  => 18,
   'cyan'  => 14, 
   'pink'  => 18
   'brown' => 18
);

is there a way while initializing the array to set similar values at once? like

'red' && 'green' =>7, 
'blue' && 'pink' && 'brown' => 18,
'cyan' =>14

of course I'm not expecting this syntax to work but is there something that gets me the same idea?

like image 285
silow Avatar asked Jan 25 '26 09:01

silow


1 Answers

PHP Manual does not provide description of any way to do that. BTW, you may initialize values in the following way:

$myarr['red'] = $myarr['green'] = 7;
$myarr['blue'] = $myarr['pink'] = $myarr['brown'] = 18;
$myarr['cyan'] = 14;
like image 58
Kel Avatar answered Jan 27 '26 21:01

Kel