Note that there are some explanatory texts on larger screens.

plurals
  1. POSmart sorting that ignores leading zeros and date formats while sorting in PHP
    primarykey
    data
    text
    <p>I have a php script that sorts 2 multi-dimensional arrays. Now if i use plain array_multisort it jumbles the 2 arrays for certain rows because both arrays have some tricky elements</p> <p>eg: a[2][2]='35' and b[2][2]='0035'</p> <p>also, a[3][4]='+0.03' b[3][4]='+.03'</p> <p>a[4][6]='31-12-2012' b[4][6]='12/31/2012'</p> <p>Because of the above tricky element difference sorting of both arrays gives different result. I need them to sort appropriately because my req are to do one-to-match across each row for analysis purposes.</p> <p>Please suggest how do I go ahead to 'smart' sort these arrays to give same result</p> <p>i have tried something on the lines of</p> <pre><code> function sort2dArray($data) { $tmp = array(); $lineCount = count($data); foreach ($data as $lineNum =&gt; $lineData) { foreach ($lineData as $column =&gt; $value) { $tmp[$column][$lineNum] = standardize($value); } } $multiSortArgs = array(); foreach ($tmp as $column =&gt; $columnData) { array_push($multiSortArgs, $columnData, SORT_ASC); } $multiSortArgs[] = &amp;$data; call_user_func_array('array_multisort', $multiSortArgs); return $data; } function standardize($value) { if(is_numeric($value)) $pval= $value + 0; else $pval= $value; return $pval; } </code></pre> <p><strong>UPDATE: o/p from both arrays with ',' as delimiter...only considering the 0035 and 35 case</strong></p> <pre><code> BA2063,,,110Y,EFW BA2063,,,110Y,EFW BA2063,,,110Y,EFW BA2063,,,121H,ECD BA2063,,,121H,ECD BA2063,,,121H,ECD BA2063,,,0035,ESW BA2063,,,0035,EFW BA2063,,,0035,EFW BA2063,,,0035,EFW BA2063,,,1L9M,EFW BA2063,,,1L9M,EFW BA2063,,,35,ESW BA2063,,,35,EFW BA2063,,,35,EFW BA2063,,,35,EFW BA2063,,,110Y,EFW BA2063,,,110Y,EFW BA2063,,,110Y,EFW BA2063,,,121H,ECD BA2063,,,121H,ECD BA2063,,,121H,ECD </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload