$ar = [
array('select' => 'ven_id, ven_name'),
array('conditions' => array(
['col=?', $value],
['col=?', $value]
))
];
The above code is halfway there! How do i alter this so that the nested arrays also use shorthand?
Thanks!
The basic form of declaring a two-dimensional array of size x, y: Syntax: data_type array_name[x][y]; Here, data_type is the type of data to be stored.
Creating Multidimensional Arrays You can create a multidimensional array by creating a 2-D matrix first, and then extending it. For example, first define a 3-by-3 matrix as the first page in a 3-D array. Now add a second page. To do this, assign another 3-by-3 matrix to the index value 2 in the third dimension.
A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.
Short array syntax was introduced in PHP 5.4 and was added to the Drupal code standards for Drupal 8. Short array syntax is cleaner and is consistent with other programming languages, such as Python. It is also easier to see closing array statement from the closing brackets of a function.
Replace array()
with []
:
$ar = [
['select' => 'ven_id, ven_name'],
['conditions' => [
['col=?', $value],
['col=?', $value]
]]
];
I maybe missing something here but why not using the following code (as you already using []
):
<?php
$ar = [
['select' => 'ven_id, ven_name'],
['conditions' => [
['col=?', $value],
['col=?', $value]
]],
];
var_dump($ar);
Can be tested here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With