php - How to Compare Array Size In Present Iteration To Array Size In Previous Iteration -
$array_size
giving array size of array $expkey
in each iteration. on each iteration want compare present array size previous array size. how plus in on first iteration there no prev array size should not give offset index. how it. thank in advance.
<?php if (isset($_post['submit'])) { unset($_post['submit']); unset($_post['ew-language__en']); function printxml ($array) { $xml = new domdocument('1.0','utf-8'); $xpath = new domxpath($xml); $xml->formatoutput = true; $last_index_ids = array(); $parentid = array(); $i_id=0; $x=0; foreach ($array $key => $value) { $key = $key; //contains values of respective ids $attrvalue= $value; if ($array[$key] == "" || ctype_space($array[$key]) ) { $array[$key] = null; } //split unique input field names $expkey = explode("__", $key); $array_size=sizeof($expkey); echo"<pre>"; print_r($array_size); echo "</pre>"; //first tag <ew-lang> $first_key =($expkey[0]); print_r($array_size); } $xml->save("file.xml"); } printxml($_post); } ?>
on printing $array_size
output
1 1 5 5 8 8 11 11 8 8 5 5 5 5 5 5 1 1 5 5 5 5
$array
is
array ( [global] => global [ew-language__en__0__phrase__actiondeleted] => deleted [ew-language__en__0__phrase__actiondeleted__0__child_phrase__1234] => numbers [ew-language__en__0__phrase__actiondeleted__0__child_phrase__1234__0__child_phrase_1__abc] => test [ew-language__en__0__phrase__actiondeleted__1__child_phrase_2__5678] => numerics [ew-language__en__1__phrase__actioninserted] => inserted [ew-language__en__2__phrase__actioninsertedgridadd] => inserted [ew-language__en__3__phrase__actionupdated] => updated [project] => project [ew-language__en__0__phrase__actioninserted] => inserted [ew-language__en__1__phrase__actioninsertedgridadd] => inserted )
where checking array size of $expkey
array ( [0] => global ) array ( [0] => ew-language [1] => en [2] => 0 [3] => phrase [4] => actiondeleted ) array ( [0] => ew-language [1] => en [2] => 0 [3] => phrase [4] => actiondeleted [5] => 0 [6] => child_phrase [7] => 1234 ) array ( [0] => ew-language [1] => en [2] => 0 [3] => phrase [4] => actiondeleted [5] => 0 [6] => child_phrase [7] => 1234 [8] => 0 [9] => child_phrase_1 [10] => abc ) array ( [0] => ew-language [1] => en [2] => 0 [3] => phrase [4] => actiondeleted [5] => 1 [6] => child_phrase_2 [7] => 5678 ) array ( [0] => ew-language [1] => en [2] => 1 [3] => phrase [4] => actioninserted ) array ( [0] => ew-language [1] => en [2] => 2 [3] => phrase [4] => actioninsertedgridadd ) array ( [0] => ew-language [1] => en [2] => 3 [3] => phrase [4] => actionupdated ) array ( [0] => project ) array ( [0] => ew-language [1] => en [2] => 0 [3] => phrase [4] => actioninserted ) array ( [0] => ew-language [1] => en [2] => 1 [3] => phrase [4] => actioninsertedgridadd )
maybe try , store before , after value after calculating final ($array_size
):
<?php $arr[] = 1; $arr[] = 3; $arr[] = 4; $arr[] = 1; // hypothetical loop demonstrate concept // representing loop: foreach ($array $key => $value) foreach($arr $array_size) { //******************************************************// // code gets to final count here //******************************************************// $calculated = $array_size; if(isset($check)) { if($calculated < $check) echo $calculated.' less '.$check; else echo $calculated.' more '.$check; echo '<br />'; } else echo $calculated.' first'."<br />"; $check = $array_size; } ?>
gives you:
1 first 3 more 1 4 more 3 1 less 4
Comments
Post a Comment