Element 1 of the following array represents the element with the greatest x value, and element 2 represents the element with the smallest x element.
Without looping over each array using PHP code, how can the index of the element with the greatest and smallest x be determined?
$array = [
['x'=>5,'y'=>3],
['x'=>9,'y'=>3],
['x'=>3,'y'=>3],
['x'=>7,'y'=>3]
];
array_column()does not loop through the entire array, because it does. And you could use a simple foreach loop and then you would only loop over the array once and not like witharray_column()twice.array_column()you not only have to loop over the array once to get the column, but also need to usemin()andmax(), which also needs to loop over the entire array. So in total you iterate over your array 3 times, just because you don't want to see "the loop" in your code. You could use a simple foreach loop and do everything in just one loop!Without looping over each- do you mean: 1) don't use aforeachloop statement 2) Use some instructions that don't compare adjacent entry values? 1) is satisfied using the 'array_*' functions. 2) Is not possible with any computer that uses a standard CPU and memory. To make it clear - all conventional computers always loop over the data.