How to store the data into an array in numeric form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahana

    #1

    How to store the data into an array in numeric form?

    i have got information posted from html form into a php file. i have accessed it through $_POST array. now i want to store these values in an array in numeric form but they always turn out to be string. i have to generate pie charts using it but it is not working as the rest of the code will only accept integer data. what should i do?

    Code:
    <?php
    require_once ('C:\wamp\www\new project\jp_graph\src\jpgraph.php');
    require_once ('C:\wamp\www\new project\jp_graph\src\jpgraph_pie.php');
    require_once ('C:\wamp\www\new project\jp_graph\src\jpgraph_pie3d.php');
    
    $d1=$_POST['s1'];
    $d2=$_POST['s2'];
    $d3=$_POST['s3'];
    $d4=$_POST['s4'];
    $d5=$_POST['s5'];
    
    $data= array($d1,$d2,$d3,$d4,$d5);
    
    //there is no error in this part of the code
    //it works fine if i pass integer values in array.
    $graph = new PieGraph(400,200,'auto');
    $graph->SetShadow();
    
    // Set A title for the plot
    $graph->title->Set("3D Pie Client side image map");
    $graph->title->SetFont(FF_FONT1,FS_BOLD);
    
    // Create
    $p1 = new PiePlot3D($data);
    $p1->SetLegends(array("Jan (%d)","Feb","Mar","Apr","May","Jun","Jul"));
    $targ=array("pie3d_csimex1.php?v=1","pie3d_csimex1.php?v=2","pie3d_csimex1.php?v=3",
    			"pie3d_csimex1.php?v=4","pie3d_csimex1.php?v=5","pie3d_csimex1.php?v=6");
    $alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
    $p1->SetCSIMTargets($targ,$alts);
    
    // Use absolute labels
    $p1->SetLabelType(1);
    $p1->value->SetFormat("%d kr");
    
    // Move the pie slightly to the left
    $p1->SetCenter(0.4,0.5);
    
    $graph->Add($p1);
    
    
    // Send back the HTML page which will call this script again
    // to retrieve the image.
    $graph->StrokeCSIM();
    
    
    
    ?>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Code:
    $x = (int) $_POST['key'];

    Comment

    Working...