Jump to content

explode() to numbers instead of strings


PeterPopper

Recommended Posts

I need help using the explode function and having the results as numbers, not strings:

 

//this is the first line of the textFiles being read from:

60,66,61,87,87,76,68,70,69,66,69,73,70

 

while(! feof($fileOpening))

  {

$externalDataRetrieved[] = rtrim(fgets($fileOpening));

  }

 

$theChartData = explode (",", $externalDataRetrieved[0]);

 

The results in $theChartData are all strimngs and not numbers

Link to comment
https://forums.phpfreaks.com/topic/181158-explode-to-numbers-instead-of-strings/
Share on other sites

You want these functions:

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

http://us3.php.net/manual/en/function.array-map.php

 

here you go:

$theChartData = array_map('intval',$theChartData);

 

 

I need help using the explode function and having the results as numbers, not strings:

 

//this is the first line of the textFiles being read from:

60,66,61,87,87,76,68,70,69,66,69,73,70

 

while(! feof($fileOpening))

  {

$externalDataRetrieved[] = rtrim(fgets($fileOpening));

  }

 

$theChartData = explode (",", $externalDataRetrieved[0]);

 

The results in $theChartData are all strimngs and not numbers

Thanks very much for the prompt and very helpful replies. This is what I did while waiting for a response:

 

foreach ($theChartData as $key => $value)

{

$theChartDataNew[$key]= (int)str_replace('"','',$value);

}

 

 

knsito and Daniel0, that is the solution, it worked perfectly. Thanks.

 

HavokDelta6, that is a cool tip that I have never seen. Thanks, mate.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.