I am trying to use a formula which requires me to mix the characters of a variable around. I am fairly new to PHP and am slightly confused with the lack of format specifications like in other languages.
the php script is being passed/(POST) two objective-c integers from my app, here is my php code I have so far, its pretty simple its more of a proof of concept and figuring out if the variable coming into my script is still int or a string or whatever the heck it might be.. slightly confused with php and the lack of having to declare format specifications etc.
<?php
$inputDate = $_REQUEST['userDate']; //example of whats coming in 12345678
//swap the 4 characters around
//23416587 (this is not random)
//then send result back
?>
So, the first question would be, when $inputDate is instantiated with ‘12345678’ is it an integer? or can I still perform string manipulation to mix the numbers like I have shown above?
The original value of
$_REQUEST['userDate'];is probably a string. To be safe, cast it with(string)$_REQUEST['userDate']or append an empty string. To get the order you desire, you could do:Since you are fairly new to PHP, let me just say that var_dump and error reporting are your friends: