Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is extra code in a Drupal view table template so $row = the content I get..

var_dump($row);

// output:
array(5) { 
    ["field_datum"]=> string(0) "" 
    ["field_werf"]=> string(9) "Comis Cui" 
    ["field_machine"]=> string(17) "Graafmachien D293" 
    ["field_aantal_uren"]=> string(1) "5" 
    ["view_node"]=> string(50) "Bekijk" 
}

$uren = $row['field_aantal_uren'];
var_dump($uren);

// output: string(1) "5" string(1) "7" string(1) "1"

I've tried everything from explode, str_replace, preg_replace to get the 3 strings in an array so I can loop over them them and make a sum. But I can't make it work..

Any suggestions to transform this variable to an array?

share|improve this question
$var1 + $var2 + $var3 ??? – str Apr 25 at 10:44
show us your code .. not just output – Svetlio Apr 25 at 10:44
I think your question is incomplete – S.Visser Apr 25 at 10:45
please post more code, your question makes no sense else... – Bartdude Apr 25 at 10:45
updated @Svetlio – Pieter Moeyersons Apr 25 at 10:52
show 2 more comments

1 Answer

up vote 1 down vote accepted

you are var_dumping from within a loop. try this:

$uren[] = $row['field_aantal_uren'];

and then OUTSIDE of the loop, you have your array.

echo array_sum($uren);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.