Jump to content

Archived

This topic is now archived and is closed to further replies.

enkidu72

for foreach each or ...? *SOLVED*

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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  ...




Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.