Note that there are some explanatory texts on larger screens.

plurals
  1. POarray issues when using ajax
    primarykey
    data
    text
    <p>I am trying to use ajax to compare two arrays to see if a particular value set is the same or not, so I filled both arrays with the same values and when i tested them my test says that they are not the same. The first array was made on fileA.php (with a while loop pulling directly from a database)and uses ajax to send it as a url variable to fileB.php (the responding file). On fileB.php I then use a $_GET to get the array , and create another array with a while loop pulling the exact same values directly from the database and compare the two . At this point the two arrays should be the same, but as I said earlier my test says they aren't .So I did a var_dump of both arrays and they looked different for some reason.</p> <p>first array dump:</p> <pre><code> array(2) { [0]=&gt; array(0) { } [1]=&gt; string(6) ",2,2,1" } </code></pre> <p>second array dump:</p> <pre><code>array(3) { [0]=&gt; array(0) { } [1]=&gt; string(1) "2" [2]=&gt; string(1) "2" [3]=&gt; string(1) "1" } </code></pre> <p>array 1 is made on fileA.php</p> <pre><code> while ($row = mysql_fetch_assoc($res)) { $iState[] = $row["state"]; }///end while </code></pre> <p>then i use ajax to send to fileB.php</p> <pre><code> js_array=&lt;? echo json_encode($iState); ?&gt;; var url_js_array=js_array.join(','); xmlhttp.open("GET","fileB.php?istate="+ url_js_array,true); xmlhttp.send(); </code></pre> <p>then in fileB.php(ajax response file) i retrieve the array</p> <pre><code> $iStateValues[] =$_GET["istate"] ; </code></pre> <p>then I create array 2 on fileB.php</p> <pre><code> while ($row = mysql_fetch_array($res)) { $currentiState[]= $row["state"]; }///end while </code></pre> <p>then I compred the two</p> <pre><code> echo"\n\nsame test\n"; if($iStateValues==$currentiState) echo "same"; else echo "not same"; </code></pre> <p>The var_dumps of the two arrays are different but they were created the exact same way . Wh is this?????</p>
    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