enkidu72 Posted September 26, 2006 Share Posted September 26, 2006 Hello all , I have several if like those :if(!isset($_POST['criterio_1'])){$_POST['criterio_1'] = ""; }if(!isset($_POST['corrispondenza_1'])){ $_POST['corrispondenza_1'] = ""; }if(!isset($_POST['criterio_2'])){$_POST['criterio_2'] = ""; }if(!isset($_POST['criterio_2'])){$table="";}I'd like to change them for something like :$array = array( $_POST['criterio_1'] , $_POST['corrispondenza_1'], $_POST['criterio_2'] );$var=each($array);if (!isset($var)){ $var="";}But I have no success :D Someone could help ?Thx in advance David Quote Link to comment Share on other sites More sharing options...
Barand Posted September 26, 2006 Share Posted September 26, 2006 This will create variable $criterio_1, $corrispondenza_1 and $criterio_2[code]<?php$array = array( 'criterio_1' , 'corrispondenza_1', 'criterio_2' ); foreach ($array as $item) { if (!isset($_POST[$item])) $$item = ''; else $$item = $_POST[$item];}?>[/code] Quote Link to comment Share on other sites More sharing options...
enkidu72 Posted September 26, 2006 Author Share Posted September 26, 2006 Thx Barand ! Quote Link to comment Share on other sites More sharing options...
enkidu72 Posted September 27, 2006 Author Share Posted September 27, 2006 It's possible that :if (!isset($_POST[$item])) $$item = ''; has to be :if (!isset($_POST[$item])){$_POST[$item]=''} ?anyway seems that i have some problem with else $$item = $_POST[$item];because I always have a notice of undefined variable ... Quote Link to comment Share on other sites More sharing options...
enkidu72 Posted October 3, 2006 Author Share Posted October 3, 2006 Maybe someone is interested in this ...Finally I figured out that has to be :[code]<?$array = array( 'criterio_1' , 'corrispondenza_1', 'criterio_2' ); foreach ($array as $item) { if (!isset($_POST[$item])){$_POST[$item] = ' ';$$item=' ' }else{ $$item = $_POST[$item]; }}?>[/code] Quote Link to comment 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.