A
A
Alexey Chernov2015-08-14 10:31:16
PHP
Alexey Chernov, 2015-08-14 10:31:16

There is no "Add topic" button, where can I find it?

b507bcd196714e8f8f06f10487548639.png
Free Wordpress account, no "Add Theme" button

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2019-02-06
@pritchin_maxim1

In a PHP associative array, the order always follows the order in which the keys were added to it.

$array = [
  [
    "gq_address" => "188.120.254.140",
    "gq_hostname" => "•   RGPlay | DarkRP [Быстрая загрузка]",
    "gq_maxplayers" => 128,
    "gq_numplayers" => 0,
    "gq_online" => true,
    "gq_port_client" => 27015,
  ], [
    "gq_address" => "62.109.18.242",
    "gq_hostname" => "Default Breach Server",
    "gq_maxplayers" => 128,
    "gq_numplayers" => 0,
    "gq_online" => true,
    "gq_port_client" => 27015,
  ]
];
$array = array_map(function($el) {
  return [
    'gq_hostname' => $el['gq_hostname'],
    'gq_address' => $el['gq_address'],
    'gq_port_client' => $el['gq_port_client'],
    'gq_online' => $el['gq_online'],
    'gq_numplayers' => $el['gq_numplayers'],
    'gq_maxplayers' => $el['gq_maxplayers']
  ];
}, $array);
var_dump($array);

array(2) {
  [0] => array(6) {
    ["gq_hostname"] => string(55) "•   RGPlay | DarkRP [Быстрая загрузка]"
    ["gq_address"] => string(15) "188.120.254.140"
    ["gq_port_client"] => int(27015)
    ["gq_online"] => bool(true)
    ["gq_numplayers"] => int(0)
    ["gq_maxplayers"] => int(128)
  }
  [1] => array(6) {
    ["gq_hostname"] => string(21) "Default Breach Server"
    ["gq_address"] => string(13) "62.109.18.242"
    ["gq_port_client"] => int(27015)
    ["gq_online"] => bool(true)
    ["gq_numplayers"] => int(0)
    ["gq_maxplayers"] => int(128)
  }
}

I
Igor Vorotnev, 2019-02-06
@HeadOnFire

uksort() function

// Берем входящий массив:
$input = [
  [
    'gq_address'     => '188.120.254.140',
    'gq_hostname'    => '•   RGPlay | DarkRP [Быстрая загрузка]',
    'gq_maxplayers'  => 128,
    'gq_numplayers'  => 0,
    'gq_online'      => true,
    'gq_port_client' => 27015,
  ],
  [
    'gq_address'     => '62.109.18.242',
    'gq_hostname'    => 'Default Breach Server',
    'gq_maxplayers'  => 128,
    'gq_numplayers'  => 0,
    'gq_online'      => true,
    'gq_port_client' => 27015,
  ],
];

// Определяем желаемый порядок ключей:
$order = [
  'gq_hostname',
  'gq_address',
  'gq_port_client',
  'gq_online',
  'gq_numplayers',
  'gq_maxplayers',
];

// Перебираем элементы входящего массива и сортируем их по ключам:
$output = array_map( function($array) use ($order)
{
        // Эта функция сортирует по ключам
  uksort( $array, function($a, $b) use ($order)
  {
    $a_desired_position = array_search($a, $order, true);
    $b_desired_position = array_search($b, $order, true);

                // Вот тут вся магия:
                // нужно вернуть отрицательное число, 0 или положительное число, 
                // в зависимости от положения одного элемента относительно другого.
    return $a_desired_position - $b_desired_position;
  } );

  return $array;
}, $input );

var_dump($input);
var_dump($output);

Here is what we end up with:
// Входящий массив:
array:2 [▼
  0 => array:6 [▼
    "gq_address" => "188.120.254.140"
    "gq_hostname" => "•   RGPlay | DarkRP [Быстрая загрузка]"
    "gq_maxplayers" => 128
    "gq_numplayers" => 0
    "gq_online" => true
    "gq_port_client" => 27015
  ]
  1 => array:6 [▼
    "gq_address" => "62.109.18.242"
    "gq_hostname" => "Default Breach Server"
    "gq_maxplayers" => 128
    "gq_numplayers" => 0
    "gq_online" => true
    "gq_port_client" => 27015
  ]
]
// Отсортированный массив:
array:2 [▼
  0 => array:6 [▼
    "gq_hostname" => "•   RGPlay | DarkRP [Быстрая загрузка]"
    "gq_address" => "188.120.254.140"
    "gq_port_client" => 27015
    "gq_online" => true
    "gq_numplayers" => 0
    "gq_maxplayers" => 128
  ]
  1 => array:6 [▼
    "gq_hostname" => "Default Breach Server"
    "gq_address" => "62.109.18.242"
    "gq_port_client" => 27015
    "gq_online" => true
    "gq_numplayers" => 0
    "gq_maxplayers" => 128
  ]
]

Conclusion: learn materiel.

V
Villarou, 2015-08-14
@Limme

You can't add your themes there on a free account. Just choose from those offered.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question