Force array to have all widgets in string

Asked

Viewed 55 times

0

$values_x = array();
for ($i = 0; $i < count( $series[0]['data'] ); $i++ ) {
    $values_x[] = $series[0]['data'][$i][0];
}

$values_y = array();
for ($i = 0; $i < count( $series[0]['data'] ); $i++ ) {
    $values_y[] = $series[0]['data'][$i][1];
}

$categories = array(
    "label"  => $label_x,
    "values" => $values_x,
    "colors" => $eco_chart_colors,
);

$series = array("label" => null, "values" => array( array("data" => $values_y)));

} else {

    $categories = array(
        "label"  => $label_x,
        "values" => $values_x,
        "colors" => "",
    );

    $series = array("label" => $label_y, "values" => $series);

}

The variable $value_x comes as numbers, ex: 2010, 2011, 2012, but I need them to be strings ex: '2010','2011', '2012'. Preferably wanted to force everything inside the $categories to be string, I’ve tried with strval but it always gives me values: null.

  • Try to do it like this here: $values_x[] = (string)$series[0]['data'][$i][0]; Read more about typecasting here

  • @Juniornunes: This comment of yours has a damned face of response. Why not write a?

  • @Wtrmute why I’m still wondering if this is what he wants, if he gives positive feedback I publish the answer!

  • Didn’t work no. Maybe it’s easier to force $Categories to string. $Categories = array( "label" => $label_x, "values" => $values_x, "Colors" => "", ); here

  • https://i.stack.Imgur.com/50Opv.png precise content of this "values" to appear as string

  • @user70531 is that $values_x is actually the label, put in $values_y: $values_y[] = (string)$series[0]['data'][$i][1];

  • no, $values_x is what’s giving values in json

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.