Jump to content

Storing this in a variable


matt0268

Recommended Posts

Doing some bitmasking, how do i store this in a variable/temp variable?

 

 

 
$val = 128;
$places = $_GET['action'];
$res = $val >> $places;
p($res, $val, '>>', $places);
 
 
function p($res, $val, $places, $note = '') {
    $format = '%0' . (PHP_INT_SIZE * 1) . "b\n";
    printf($format, $res);
 
 
 
}
Link to comment
https://forums.phpfreaks.com/topic/282700-storing-this-in-a-variable/
Share on other sites

Change your function to return the value instead of echo

$val = 128;
$places = $_GET['action'];
$res = $val >> $places;
$stored = p($res, $val, '>>', $places);
 
 
function p($res, $val, $places, $note = '') {
    $format = '%0' . (PHP_INT_SIZE * 1) . "b\n";
    return sprintf($format, $res); 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.