0

the following is working code:

        $openchart->type("BarChart");
    $openchart->options(array('title' => "Opens Stats"));
    $openchart->columns(array(
        'Date' => array(
            'type' => 'string',
            'label' => 'Date'
        ),
        'yahoo.com' => array(
            'type' => 'number',
            'label' => 'yahoo.com'
        )
    ));

    $openchart->addRow(array('Date' => "Today", 'yahoo.com'=> $chart['yahoo.com']['opentoday']));

what I want to be able to do is like the following, but not sure how to accomplish.

        $openchart->type("BarChart");
    $openchart->options(array('title' => "Opens Stats"));
    $openchart->columns(array(
        'Date' => array(
            'type' => 'string',
            'label' => 'Date'
        ),
foreach($chart[$name])
        '$name' => array(
            'type' => 'number',
            'label' => '$name'
        )
    ));

    $openchart->addRow(array('Date' => "Today", '$name'=> $chart['$name']['opentoday']));

is this possible? still very new to PHP. am also using CakePHP (and learning a TON by just trial and error!)

Originally I just tried

$openchart->columnts( array(           
            '$name' => array(
            'type' => 'number',
            'label' => '$name'
        ));

but that overwrote the array. also checked out array_merge, but that wasn't working, and not sure why.

so now at the end of my first foreach (not shown), I have an array of all the values I want, in $chart[$name]

and figured that might be best route to then do the 'columns' all at once.

love that this site exists, getting so much accomplished. thank you!

brizz
  • 271
  • 1
  • 6
  • 17
  • Just a couple pointers... Putting `$variables` inside `'$single_quotes'` will effectively make the variable a literal string. Use `"$double_quotes"` instead. Also, the syntax is incorrect for your `foreach` loop: see [this page](http://php.net/manual/en/control-structures.foreach.php) for more on that. Finally, it doesn't look like `$chart` or `$name` has been defined before it's run through `foreach` which means PHP is saying to itself, "For each _what_? _$chart_? No one has told me what `$chart` means, so I don't know what to do." – jerdiggity Sep 28 '13 at 03:08
  • yea after posting realized the mock up was syntaxly wrong for that variable. ....but beyond that, is what I want to do possible w/current PHP? I didn't include the $chart or $name for simplicity sake. [just wanna know if its possible to do a foreach type statement within a object (hope I'm using correct terms..literally learned arrays and objects by fooling w/code. reading 2 learn was to slow and not enough 'coding' to reading ratio.)] – brizz Sep 28 '13 at 03:23

1 Answers1

0

is this what you were wondering?

class test{
    public $array = array("foo", "bar");

    public function __construct(){}
}

$test = new test();

foreach($test->array as $key=>$value){
    echo "$key=>$value\n";
}

output is 0=>foo 1=>bar

scorm
  • 63
  • 5
  • I saw a post similar to this when I was trying to find solution. ...not sure what 'construct' is ...but probably. Will get back to you. Figured I'd give my 'thoughts' as others have been so helpful to me in figuring things out. – brizz Sep 28 '13 at 03:36
  • based on this: http://stackoverflow.com/questions/455910/what-is-the-function-construct-used-for .probably so. wanted to dive in, and stackoverflow lets me :). ..will confirm solution in a bit w/any comments. – brizz Sep 28 '13 at 03:43