Jbert2 Posted July 5, 2008 Share Posted July 5, 2008 Is there a better and faster way to replace the whole array instead of using something like this $extract = array_splice($myArray,0,$myReplacement); Thanks Jim Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/ Share on other sites More sharing options...
teynon Posted July 5, 2008 Share Posted July 5, 2008 What exactly are you trying to do? Please explain in more detail. Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582256 Share on other sites More sharing options...
.josh Posted July 5, 2008 Share Posted July 5, 2008 if you're wanting to just straight replace the array with something completely new, without preserving anything, simply assign your new array to the old array. Example: <?php $x = array (1,2,3); $y = array (4,5,6); print_r($x); // old array echo "<br/>"; $x = $y; // assign new array print_r($x); // new array ?> Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582261 Share on other sites More sharing options...
DarkWater Posted July 5, 2008 Share Posted July 5, 2008 Yeah....You could even do: $x = array(2, 3, "lol" => "lol"); print_r($x); $x = array(3, 9431, "this" => "fun"); print_r($x); Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582262 Share on other sites More sharing options...
Jbert2 Posted July 5, 2008 Author Share Posted July 5, 2008 Here is the part of code for the array $im = imagecreatefromjpeg('images/tree.jpg'); $matrix = array( array(2,2,-2), array(2,1,-1), array(2,-2,-2) ); makeFilter($im, $matrix); It was listed in 3 parts b/c that is the way a 3x3 matrix list variables. So what I want to do is from an input form, if i choose say "sepia" for a filter, I wantthe code for a sepia filter to be put in the array and the script run. When done it would display the sepia filter on the original. Your thoughts appreciated JIM Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582337 Share on other sites More sharing options...
wildteen88 Posted July 5, 2008 Share Posted July 5, 2008 Something like <?php if(isset($_POST['submit'])) { switch($_POST['filter']) { case 'sepia': $matrix = array( array(2, 2, -2), array(2, 1, -1), array(2, -2, -2) ); break; case 'filter2': $matrix = array( array for fiter2 ); break; case 'filter3': $matrix = array( array for fiter3 ); break; } $im = imagecreatefromjpeg('images/tree.jpg'); makeFilter($im, $matrix); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Filter:<br /><input type="radio" name="filter" value="sepia"> Sepia<br /> <input type="radio" name="filter" value="filter2"> Filter2<br /> <input type="radio" name="filter" value="filter3"> Filter3<br /> <input type="submit" name="submit" value="Apply Filter"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582432 Share on other sites More sharing options...
Jbert2 Posted July 5, 2008 Author Share Posted July 5, 2008 Wildteen88, thanks for the great use of the switch. Take a look at this and see if it can be added. I was using it in my original script here if ($input == 1) [b]{ header("location: rockets.php"); }[/b] else if ($input == 2) { header ("Location: loops.php"); } else if ($input == 3) { header ("Location: 2kernel2.php"); } [\code] I started merging the new code and tried this [code] switch($_POST['filter']) { [b]case 'rocket': { header("location: rockets.php"); }[/b] break; case 'sepia': $matrix = array( array(2, 2, -2), array(2, 1, -1), array(2, -2, -2) ); break; Here is the line from the input form [code]<input type="radio" name="filter" value="rocket">Rockets<br /> but it is not connecting to the page. Thanks JIM [/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582514 Share on other sites More sharing options...
Jbert2 Posted July 5, 2008 Author Share Posted July 5, 2008 Must need some other way. Other lines in script expecting an array only & it causes an invalid argument, so page will not work for sure Quote Link to comment https://forums.phpfreaks.com/topic/113328-array-replacement/#findComment-582516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.