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 Link to comment https://forums.phpfreaks.com/topic/22157-for-foreach-each-or-solved/ 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] Link to comment https://forums.phpfreaks.com/topic/22157-for-foreach-each-or-solved/#findComment-99207 Share on other sites More sharing options...
enkidu72 Posted September 26, 2006 Author Share Posted September 26, 2006 Thx Barand ! Link to comment https://forums.phpfreaks.com/topic/22157-for-foreach-each-or-solved/#findComment-99270 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 ... Link to comment https://forums.phpfreaks.com/topic/22157-for-foreach-each-or-solved/#findComment-99526 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] Link to comment https://forums.phpfreaks.com/topic/22157-for-foreach-each-or-solved/#findComment-102900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.