www.webdeveloper.com
Results 1 to 5 of 5

Thread: Need to store numbers in the array

  1. #1
    Join Date
    Jun 2008
    Posts
    118

    Need to store numbers in the array

    OK
    I am importing a CSV file which holds 3 sets of data.

    2 of the sets holding numbers for use as coordinates in JGraph.

    When I am supplying these numbers into arrays they are stored as strings and I need them to be stored as integers.

    I tried using settype(),but to no avail

    any ideas?

  2. #2
    Join Date
    Jun 2008
    Posts
    118
    PHP Code:
    foreach ($file_content as $line){
            
            
    $values=explode(','$line);
            
    $x_axis=$values[1];
            
    $y_axis=$values[2];
            
    settype($x_axis'int');
            
    settype($y_axis'int');
            
    array_push($_SESSION['names'], $values[0]);
            
    array_push($_SESSION['x_axis'], $x_axis);
            
    array_push($_SESSION['y_axis'], $y_axis);
            
        } 

  3. #3
    Join Date
    Jun 2007
    Posts
    400
    Do you know what version of PHP you are running? Apparently before 4.2.0 you had to user 'integer' instead of 'int'?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    It normally should not matter, as PHP is a "loosely typed" language and will convert types automatically when required, at least in the vast majority of cases. But if you really need to cast it to an integer, the simplest way is:
    PHP Code:
    $x_axis= (int) $values[1]; 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jun 2008
    Posts
    118
    I am running PHP 5

    I'll try NogDogs advice, though it's prety bad for me to forget about it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles