how can check integer or string value in array

<?php
function get_data($url){
   $ch = curl_init();
  $timeout = 0;
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $response=json_decode(curl_exec($ch),true);
	curl_close($ch);
    return $response;
}

$url='http://212.76.95.85:8844/CreateHWB.aspx?from=RYD&to=DMM&shipid=1223456789&shipssn=0&shipname=mohamad&shipphone=098765&shipcity=riyadh&shipaddress=Riyadh-Olayia&rcvssn=0&rcvname=toto&rcvphone=0546445819&rcvcity=dammam&rcvaddress=dammam-Raka%20&pkgdesc=IPHONE&codvalue=1700&pcs=1&customerno=110004&weight=3&passcode=TestPassword&refno=0';
$response=get_data($url);
print_r($response);
if(is_int($response[0][0]==true)) {
$$object=$response[0][0];
}else{
$object=$response[0][0];
echo '<font color="#cc0000">message:: '.$object.'</font>';
	exit();
}

?>

Open in new window

Hamdan ShafiqPHP Full Stack DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
The general method to do this is via gettype() method ie:
$data = array(1, 1., NULL, new stdClass, 'foo');

foreach ($data as $value) {
    echo gettype($value), "\n";
}

Open in new window

Now in your php code wich is the array var?
0
NerdsOfTechTechnology ScientistCommented:
If $response[0][0] wasn't a string, then you would correct this line, from:
if(is_int($response[0][0]==true)) {

Open in new window

to
if(is_int($response[0][0])) {

Open in new window


$response[0][0]==true evaluates as true unless $response[0][0] is:

the boolean FALSE itself
the integer 0 (zero)
the float 0.0 (zero)
the empty string, and the string "0"
an array with zero elements
the special type NULL (including unset variables)

http://php.net/manual/en/language.types.boolean.php

HOWEVER, since $response[0][0] is a string you'll want to check if the variable is numberic first, then cast it as integer (if you desire), like this:

if(is_numeric($response[0][0])) {
   $response[0][0]=intval($response[0][0]);

Open in new window

http://php.net/manual/en/function.intval.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.