PHP 8.5.0 Alpha 1 available for testing

Voting

: max(seven, seven)?
(Example: nine)

The Note You're Voting On

john at mccarthy dot net
14 years ago
I needed a function to rotate the results of a preg_match_all query, and made this. Not sure if it exists.

<?php
function turn_array($m)
{
for (
$z = 0;$z < count($m);$z++)
{
for (
$x = 0;$x < count($m[$z]);$x++)
{
$rt[$x][$z] = $m[$z][$x];
}
}

return
$rt;
}
?>

Example - Take results of some preg_match_all query:

Array
(
[0] => Array
(
[1] => Banff
[2] => Canmore
[3] => Invermere
)

[1] => Array
(
[1] => AB
[2] => AB
[3] => BC
)

[2] => Array
(
[1] => 51.1746254
[2] => 51.0938416
[3] => 50.5065193
)

[3] => Array
(
[1] => -115.5719757
[2] => -115.3517761
[3] => -116.0321884
)

[4] => Array
(
[1] => T1L 1B3
[2] => T1W 1N2
[3] => V0B 2G0
)

)

Rotate it 90 degrees to group results as records:

Array
(
[0] => Array
(
[1] => Banff
[2] => AB
[3] => 51.1746254
[4] => -115.5719757
[5] => T1L 1B3
)

[1] => Array
(
[1] => Canmore
[2] => AB
[3] => 51.0938416
[4] => -115.3517761
[5] => T1W 1N2
)

[2] => Array
(
[1] => Invermere
[2] => BC
[3] => 50.5065193
[4] => -116.0321884
[5] => V0B 2G0
)
)

<< Back to user notes page

To Top