Как сделать массив чисел значением - PullRequest
0 голосов
/ 01 апреля 2020

Как сделать значение 0 =>, 1 => 2 => «marketplace_name»

array (size=4)
  0 => 
    array (size=7)
      'marketplace_name' => string 'Amazon' (length=6)
      'marketplace_affiliate_code' => string 'amazon-20' (length=9)
      'button_line_colour' => string '#000000' (length=7)
      'button_text_colour' => string '#000000' (length=7)
      'button_background_colour' => string '#eeee22' (length=7)
      'button_text' => string '#caa75b' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/amazon-icon-1.png' (length=79)
  1 => 
    array (size=7)
      'marketplace_name' => string 'BCF' (length=3)
      'marketplace_affiliate_code' => string 'ebay-30' (length=7)
      'button_line_colour' => string '#004b8d' (length=7)
      'button_text_colour' => string '#004b8d' (length=7)
      'button_background_colour' => string '#004b8d' (length=7)
      'button_text' => string '#81d742' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/bcf.png' (length=69)
  2 => 
    array (size=7)
      'marketplace_name' => string 'Macpac' (length=6)
      'marketplace_affiliate_code' => string 'Macpac-10' (length=9)
      'button_line_colour' => string '#ef491f' (length=7)
      'button_text_colour' => string '#ef491f' (length=7)
      'button_background_colour' => string '#ef491f' (length=7)
      'button_text' => string '#ffffff' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/macpac.png' (length=72)

как-то так, я хочу, чтобы оно было таким, как показано ниже, чтобы я мог так называть эти рынки что я могу использовать его элементы на определенном рынке.

array (size=4)
  Amazon => 
    array (size=7)
      'marketplace_name' => string 'Amazon' (length=6)
    ...
  BCF => 
    array (size=7)
      'marketplace_name' => string 'BCF' (length=3)
    ...
  Macpac => 
    array (size=7)
      'marketplace_name' => string 'Macpac' (length=6)
    ...

Ответы [ 3 ]

0 голосов
/ 01 апреля 2020

Вот код. Надеюсь, это поможет вам.

$data = array(
    array(    
        'marketplace_name' => 'Amazon',
        'marketplace_affiliate_code' => 'amazon-20'
    ),
    array(    
        'marketplace_name' => 'BCF',
        'marketplace_affiliate_code' => 'ebay-30'
    ),
    array(    
        'marketplace_name' => 'Macpac',
        'marketplace_affiliate_code' => 'Macpac-10'
    )
);

foreach( $data as $index => $datum ) {
    $marketplace_name = $datum['marketplace_name'];
    unset( $data[ $index ] );
    $data[ $marketplace_name ] = $datum;
}
0 голосов
/ 01 апреля 2020

Это то, что я сделал

$marketplace_list_button_styles = get_field('marketplace_list', option);

foreach ($marketplace_list_button_styles as $style) {
    $mp[] = $style['marketplace_name'];
}

$final_array = array_combine($mp, $marketplace_list_button_styles);

var_dump($final_array);

, так что теперь это выглядит так

array (size=4)
  'Amazon' => 
    array (size=7)
      'marketplace_name' => string 'Amazon' (length=6)
      'marketplace_affiliate_code' => string 'amazon-20' (length=9)
      'button_line_colour' => string '#000000' (length=7)
      'button_text_colour' => string '#000000' (length=7)
      'button_background_colour' => string '#eeee22' (length=7)
      'button_text' => string '#caa75b' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/amazon-icon-1.png' (length=79)
  'BCF' => 
    array (size=7)
      'marketplace_name' => string 'BCF' (length=3)
      'marketplace_affiliate_code' => string 'ebay-30' (length=7)
      'button_line_colour' => string '#004b8d' (length=7)
      'button_text_colour' => string '#004b8d' (length=7)
      'button_background_colour' => string '#004b8d' (length=7)
      'button_text' => string '#81d742' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/bcf.png' (length=69)
  'Macpac' => 
    array (size=7)
      'marketplace_name' => string 'Macpac' (length=6)
      'marketplace_affiliate_code' => string 'Macpac-10' (length=9)
      'button_line_colour' => string '#ef491f' (length=7)
      'button_text_colour' => string '#ef491f' (length=7)
      'button_background_colour' => string '#ef491f' (length=7)
      'button_text' => string '#ffffff' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/macpac.png' (length=72)
  'Tent World' => 
    array (size=7)
      'marketplace_name' => string 'Tent World' (length=10)
      'marketplace_affiliate_code' => string 'tent-20' (length=7)
      'button_line_colour' => string '#004117' (length=7)
      'button_text_colour' => string '#004117' (length=7)
      'button_background_colour' => string '#004117' (length=7)
      'button_text' => string '#ffffff' (length=7)
      'button_logo' => string 'http://localhost/website.com/wp-content/uploads/2020/03/tentworld.png' (length=75)
0 голосов
/ 01 апреля 2020

Ассоциативный массив может вам помочь:

   $amazon= array('marketplace_name' =>  'Amazon','marketplace_affiliate_code' => 'amazon-20'.... so on....);
 $bfg= array('marketplace_name' =>  'bfc','marketplace_affiliate_code' => 'ebay-30'.... so on....);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...