dataframe - PHP passing boolean to ArrayObject for inner comparison -
is there way access details of boolean passed arrayobject comparison each element of array?
i've begun work on dataframe php , seem have hit glass ceiling one.
sample code:
<?php class dataframe extends arrayobject { public function offsetget($key) { if (is_bool($key)) { echo "passed boolean: {$key}\n"; } else { echo "comparing: {$key}\n"; } } }
just simple case code:
$df = new dataframe(); $df['hello'] = 'world'; $df[$df['hello'] == 'world'];
will output (for non-null, non-false, non-zero comparison):
comparing: hello passed boolean:
otherwise:
comparing: hello passed boolean: 1
either way have no access comparison approach.
is there interface can implement in order gain access boolean comparison methods or out of reach of php? either way sugar number of other approaches can taken, shame not have classic dataframe syntax.
if mean r-like dataframe syntax, sorry php not expose such interface natively, nothing prevents implementing it.
the closest you'll array_filter
function.
for php 5.3+ can do:
$data = array('hello', 'world'); $selected = array_filter($data, function($val) { return $val === 'world'; }); var_dump($selected); // output: array(1) { 0 => world }
Comments
Post a Comment