1

I have array in php like:

if ($_GET['id1'] == "machine-category") {
    $table['cols'] = array(
        array('label' => 'category', 'type' => 'string'),
        array('label' => 'count', 'type' => 'string')
    );
}

I want to pass various value in category, tried:

if ($_GET['id1'] == "machine-category") {
    $table['cols'] = array(
        array("'".
            "label".
            "'".
            " => . ".
            "'".explode($GET['id1'], "-")[1].
            "', '".
            "type'".
            " => '".
            "string".
            "'"),
        array('label' => 'count', 'type' => 'string')
    );
}

but it doesn't work.

Can anyone provide the solution for same?

2
  • Could you provide more details on how, exactly, it is not working? Commented Mar 26, 2016 at 3:38
  • explode($GET['id1'], "-")[1] not permitted Commented Mar 26, 2016 at 3:46

1 Answer 1

2

I'm not quite sure what you're trying to accomplish. Perhaps you're saying that if your $_GET['id1'] is machine-category, you want a line that looks like this:

    array('label' => 'category', 'type' => 'string'),

and if you have a $_GET['id1'] of machine-foobar then you want a line like this:

    array('label' => 'foobar', 'type' => 'string'),

Is that what you're asking? In that case, try this:

if ($_GET['id1'] == "machine-category!") {
        $category_parts = explode('-', $_GET['id1']);
        $category = $category_parts[1];
        $table['cols'] = array(
            array('label' => $category, 'type' => 'string'),
            array('label' => 'count', 'type' => 'string')
        );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.