Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: string to array, character by character


Message #1 by "Pedro" <ufhbiqwj001@s...> on Wed, 2 Oct 2002 12:37:39 +0200
you have uninitialized variables: better initialize them :)
see below, on the lines without >

thanks for the laugh!


> -----Original Message-----
> BTW.
> 
> I think I have come up with a MUCH better way to 
> split the word "hello" into an array...
> 
> I can't be sure but I think it's very efficient.
> 
> Any improvements would be welcome.
> 
> 	Justin ;)
> 
> --starts---
> 
> <?php
> 
> 	// ======================================
> 	// Function To Split "hello" into An Array
> 
> 	// Firstly set $str = to "hello"..
> 	$var = "str";
> 	$h = "l";
> 	$l = "e";
> 	$e = "o";
> 	$o = "h";
> 
> 	${$var} = ${$e} . ${$h};
> 
> 	for ( $i=0; $i<2; $i++ )
> 	{
> 		eval("\$str .= \"" . ${$o} . "\";");
> 	}
> 
> 	${"s" . "t" . "r"} = ${$var} . ${$l};
> 
> 	// Then split $str into an array..
> 	$new_array[0] = substr($str,0,1);

      // initialize needed variables
      $x = 0;
      $c = $x * $x;
      $m = (int)($x . $c);
      $p = ((int)(isset($m))) - 1;
      $q = strlen('hello') - 5;

> 
> 	${"new" . "_" . "array"}[((($x*$c))*($m*$p*$q)+1)] = 
> 	substr(${"s" . "t" . "r"},1,1);
> 
> 	for ( $i=2; $i<4; $i++ )
> 	{
> 		$new_array[$i] = substr($str,$i,1);
> 	}	
> 
> 	array_push ($new_array, substr($str,(strlen($str)-1),1));
> 
> 
> 	// And finally lets see the array..
> 	print "<pre>";
> 	print_r($new_array);
> 	print "<pre>";
> 
> ?>
> 
> --ends--
> 


  Return to Index