Maxraid Posted November 30, 2006 Share Posted November 30, 2006 is it possible to insert variables into an array and then run trough those variables in the array one by one and makes some chances to them.example:[code]$checkboxArray = array("$rigger","$anhugger","$systemfacade");$max = sizeof($checkboxArray);//Change the value of checkboxes for($counter=1; $counter<$max; $counter++) { if ($checkboxArray[$counter] == "on") { $checkboxArray[$counter] = "YES"; } else { $checkboxArray[$counter] = "NO"; } }[/code]the if statement works if I do the variables one at the time but since i have 25 variables, I have to make the IF statement 25 times that cant be true? Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/ Share on other sites More sharing options...
Maxraid Posted November 30, 2006 Author Share Posted November 30, 2006 UPS sorry for the doubble posting Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132639 Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 this isnt tested... but it should work...foreach is MUCH faster and easier with arrays :-)[code]<?$checkboxArray = array( 1=>"$rigger", 2=>"$anhugger", 3=>"$systemfacade");foreach($checkboxArray as $k => $v){ if($v == "on") $checkboxArray[$k] = "YES"; else $checkboxArray[$k] = "NO";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132650 Share on other sites More sharing options...
CheesierAngel Posted November 30, 2006 Share Posted November 30, 2006 [quote author=taith link=topic=116821.msg476199#msg476199 date=1164894867]this isnt tested... but it should work...foreach is MUCH faster and easier with arrays :-)[code]<?$checkboxArray = array( 1=>"$rigger", 2=>"$anhugger", 3=>"$systemfacade");foreach($checkboxArray as $k => $v){ if($v == "on") $checkboxArray[$k] = "YES"; else $checkboxArray[$k] = "NO";}?>[/code][/quote]And the shortest way to do:[code]<?php$checkboxArray = array( 1=>"$rigger", 2=>"$anhugger", 3=>"$systemfacade");foreach($checkboxArray as $k => $v){ $checkboxArray[$k] = $v == "on" ? "Yes" : "No";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132666 Share on other sites More sharing options...
Maxraid Posted November 30, 2006 Author Share Posted November 30, 2006 Thats great guys its working, I just have one small question more.Now i've change the values of variables in the array, but what if i want to print just one specifik one exam. nr 3 ;).its because i need to display the result not in a long line, but specifik places in html?echo($checkboxArray[?]);Do u get my idea Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132792 Share on other sites More sharing options...
alpine Posted November 30, 2006 Share Posted November 30, 2006 [code]<?phpecho $checkboxArray[2];echo <<<_HTMLblah blah {$checkboxArray[2]} blah_HTML;?>[/code] Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132796 Share on other sites More sharing options...
Maxraid Posted November 30, 2006 Author Share Posted November 30, 2006 thanks alot, thats working I actually tried that earlier but got a different result, I must have made some mistakes.Anyway great help :) Link to comment https://forums.phpfreaks.com/topic/28965-solved-variables-in-a-array/#findComment-132827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.