0
Within the PHP
i add two arrays
and then I add them into a variable of a print
with JS.
<?php
$objp = array();
$objs = array();
print("<SCRIPT language=javascript>
objp = \"$objp\";
objs = \"$objs\";
n_p = new Array (10);
</SCRIPT>");
?>
Now inside the JavaScript
I use a for when I submit to add the contents of these two arrays
within the n_p
;
<script language="javascript">
for(var i = 0; i < 10; i++){
if(objp!=''){
n_p[i] = objp;
objp.shift();
}
else{
n_p[i] = objs;
objs.shift();
}
}
</script>
The problem is, I’m using the shift()
to remove the first element of array
, but when he goes inside the if
it does not perform. What could be the problem?
The function objs.shift();
is not executed!
Obs* I used the splice() but ended up not working either!
language="javascript"
is discontinued, must betype="text/javascript"
or may carry nothing in certain types of document.– Zuul
@Zuul edited the way you showed, but ended up not solving either. But I appreciate the help!
– Alexandre
It wasn’t really a help for your current problem but rather a warning about the standards :) @bfavaretto is well on the way to solving your issue!
– Zuul
What happens is simple... If you are comparing the objp array with nothing and it has something will return false. rsrs. Obvious right. If you want to check if the first location is empty you should compare the identifier of the first space: if (objp[0] != '')
– HiHello