My Zeros are disappearing!

Do you have a question?

You need to post code using the code tags, not an picture.

Thanks for your reply, I was unaware of that rule.

 <?php

//form submittion

if(isset($_POST['submit'])){
	
	//array index modifier
	$t=0;
	
	//string split ex:"111" = "1","1","1"
	$boom = array();
	
	//twenty-three decimal values equaling eight octal user entries 
	$caught = array();
	
	//loop to retrieve user input
	for($i=0;$i<8;$i++){
		//array for raw user inputs
		$raw_bite[$i]  = $_POST["raw_bit$i"];
	}
		//loop array variables through base converter and string split
		foreach($raw_bite as $value){
			//convert from octal to decimal equiv
			$raw_bits = base_convert($value,8,2);
			//split decimal equiv to three individual variables 
			$boom = (str_split("$raw_bits",1));
				//place individual variables into an array
				foreach($boom as $value){
					$caught[$t] = $value;
					$t++;
		}	
	}
	//loop through array to see all twenty three variables 
	foreach($caught as $value){
		echo $value;
	}
	
}else{
	echo "Hey! There's been an Error!";
}
?>

Output:
000 returned as 0 (I’m needing 000)
001 returned as 1 (I’m needing 001)
010 returned as 10 (I’m needing 010)
011 returned as 11 (I’m needing 011)
100 returned as 100
101 returned as 101
110 returned as 110
111 returned as 111

There’s this code button </> in the editor you can use so someone might want to read this.

An integer can not have leading 0’s. So they are removed. That is why your 000 becomes 0, 001 becomes 1 etc. So you should either use strings or add the 0’s later using sprintf() or str_pad().

Thank you BFlokstra!

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service