Reference - Data handling - first


App: manual - Page: miscellaneous/handling


App: regression/framework - Page: options/a_dotted_option_value_keeps_the_level_name
PHP
options/a_dotted_option_value_keeps_the_level_name.php
HTML
options/a_dotted_option_value_keeps_the_level_name.pad
Result
<?php

$items
= [ [ "n" => "a" ], [ "n" => "b" ], [ "n" => "c" ] ];
$cfg = [ "max" => 2 ];

?>
[{items first=$cfg.max}{$n}:{current@items}/{count@items} {/items}]


App: regression/framework - Page: options/a_level_the_handling_empties_takes_its_else_and_notok
PHP
HTML
options/a_level_the_handling_empties_takes_its_else_and_notok.pad
Result
{content 'none'}nothing{/content}{content 'oops'}bad{/content}{data 'xs'}[1,2,3]{/data}
else:[{xs where='$xs gt 5', else='none'}{$xs},{/xs}] first:[{xs first=0, else='none'}{$xs},{/xs}] notOk:[{xs where='$xs gt 5', notOk='oops'}{$xs},{/xs}] kept:[{xs where='$xs gt 1', else='none'}{$xs},{/xs}]


App: regression/framework - Page: options/a_level_the_handling_left_without_rows_renders_neither_prelude_nor_coda
PHP
options/a_level_the_handling_left_without_rows_renders_neither_prelude_nor_coda.php
HTML
options/a_level_the_handling_left_without_rows_renders_neither_prelude_nor_coda.pad
Result
<?php

$items
= [ [ 'n' => 1 ], [ 'n' => 2 ] ];
$none = [];

?>
0[{none}H@start@R@end@F{/none}] 8[{items where='$n gt 5'}H@start@R@end@F{/items}] 12[{items first=0}H@start@R@end@F{/items}] 14[{items where='$n gt 5'}H@start@R@end@F@else@E{/items}] 15[{items where='$n gt 1'}H@start@{$n}@end@F{/items}]


App: regression/framework - Page: options/an_at_start_level_negative_and_first_left_without_rows_renders_nothing
PHP
HTML
options/an_at_start_level_negative_and_first_left_without_rows_renders_nothing.pad
Result
{data 'd'}[{"n":"a"},{"n":"b"},{"n":"c"}]{/data}<{d negative, first=3}pre @start@x@end@ post{/d}>


App: regression/framework - Page: options/first_takes_a_count_that_php_set_as_a_number
PHP
options/first_takes_a_count_that_php_set_as_a_number.php
HTML
options/first_takes_a_count_that_php_set_as_a_number.pad
Result
<?php

$cnt
= 2;

?>
{data 'd'}[{"n":"a"},{"n":"b"},{"n":"c"}]{/data}{d first=$cnt}{$n}{/d}


App: regression/framework - Page: options/first_takes_one_from_the_front
PHP
HTML
options/first_takes_one_from_the_front.pad
Result
{data 'n'}
[1,2,3,4,5,6]
{/data}
{n first}
{$n},
{/n}


App: regression/framework - Page: options/first_with_a_count
PHP
HTML
options/first_with_a_count.pad
Result
{data 'n'}
[1,2,3,4,5,6]
{/data}
{n first=2}
{$n},
{/n}


App: regression/framework - Page: options/first_zero_shows_the_else_branch
PHP
HTML
options/first_zero_shows_the_else_branch.pad
Result
[{staff first=0}{$name}@else@none{/staff}]


App: regression/framework - Page: options/group_runs_in_order_with_sort_and_first
PHP
options/group_runs_in_order_with_sort_and_first.php
HTML
options/group_runs_in_order_with_sort_and_first.pad
Result
<?php

$orders
= [
[
"number" => 1, "customer" => "bob", "total" => "10.10" ],
[
"number" => 2, "customer" => "alice", "total" => 20 ],
[
"number" => 3, "customer" => "bob", "total" => "20.20" ],
[
"number" => 4, "customer" => "alice", "total" => 7 ],
[
"number" => 5, "customer" => "carol", "total" => 1 ]
];

?>
{orders sort='total', group='customer'}[{$customer}:{rows}{$number}{/rows}]{/orders}|{orders group='customer', sum='total', sort='total DESC', first=2}[{$customer} {$total}]{/orders}|{orders group='customer', where='$count gt 1', negative}{$customer}{/orders}


App: regression/framework - Page: options/last_zero_keeps_no_row_as_first_zero_does
PHP
HTML
options/last_zero_keeps_no_row_as_first_zero_does.pad
Result
{data 'u'}[1,2,3]{/data}[{u first=0}{$u}{/u}][{u last=0}{$u}{/u}][{u last=0, negative}{$u}{/u}][{u last=2}{$u}{/u}]


App: regression/framework - Page: options/negative_inverts_the_selection_and_leaves_the_order_alone
PHP
HTML
options/negative_inverts_the_selection_and_leaves_the_order_alone.pad
Result
{data 'xs'}
[3,1,4,2]
{/data}
[{xs where='$xs gt 2', sort='xs', negative}{$xs}{/xs}]
[{xs first=2, reverse, negative}{$xs}{/xs}]


App: regression/framework - Page: options/negative_keeps_what_the_option_would_have_dropped
PHP
HTML
options/negative_keeps_what_the_option_would_have_dropped.pad
Result
{data 'n'}
[1,2,3,4,5,6]
{/data}
{n first=2, negative}
{$n},
{/n}


App: regression/framework - Page: options/negative_leaves_sort_reverse_and_shuffle_their_rows
PHP
HTML
options/negative_leaves_sort_reverse_and_shuffle_their_rows.pad
Result
{data 'n'}
[3,1,5,2,4]
{/data}
[{n where='$n gt 2', sort, negative}
{$n},
{/n}][{n first=2, reverse, negative}
{$n},
{/n}][{n sort, last=2, negative}
{$n},
{/n}][{n first=3, shuffle, negative}
x
{/n}]


App: regression/framework - Page: options/rows_keyed_by_number_keep_their_keys_under_every_handler
PHP
options/rows_keyed_by_number_keep_their_keys_under_every_handler.php
HTML
options/rows_keyed_by_number_keep_their_keys_under_every_handler.pad
Result
<?php

// A set keyed by id - the keys are part of the rows, {&key} names them - and a list, which
// stays a list: numbered from 0 again after the handler.

$ks = [ 10 => [ 'n' => 3 ], 20 => [ 'n' => 1 ], 30 => [ 'n' => 2 ] ];
$xs = [ 'a', 'b', 'c' ];

?>
first:[{ks first=2}{&key},{/ks}] last:[{ks last=2}{&key},{/ks}] reverse:[{ks reverse}{&key},{/ks}] sort:[{ks sort='n'}{&key},{/ks}] splice:[{ks splice='1|1'}{&key},{/ks}] trim:[{ks trim}{&key},{/ks}] left:[{ks trim, left}{&key},{/ks}] random:[{ks random=3, orderly}{&key},{/ks}] list:[{xs reverse}{&key}{$xs},{/xs}][{xs last=2}{&key}{$xs},{/xs}][{xs splice='0|1'}{&key}{$xs},{/xs}]