Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.