0

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?

6
  • $var1 + $var2 + $var3 ??? Commented Apr 25, 2013 at 10:44
  • show us your code .. not just output Commented Apr 25, 2013 at 10:44
  • I think your question is incomplete Commented Apr 25, 2013 at 10:45
  • please post more code, your question makes no sense else... Commented Apr 25, 2013 at 10:45
  • in this case it outputs 'string '5' (length=1)' because this is the value of array key 'field_aantal_uren' what you need to get ? Commented Apr 25, 2013 at 10:54

1 Answer 1

1

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);
0

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.