Alguem aqui conhece alguma função no php que crie uma variavel com o nome igual ao valor de outra?
Last edited by merrik on Sun Oct 15, 2006 5:20 am; edited 1 time in total
Last edited by merrik on Sun Oct 15, 2006 5:20 am; edited 1 time in total
| merrik wrote: |
| Alguem aqui conhece alguma função no php que crie uma variavel com o valor de outra? |
| Code: |
| <?php
$action = $_GET[action]; $accept_charset = " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,W,Y,Z, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,x,w,y,z, 1,2,3,4,5,6,7,8,9, _,. "; |
| Code: |
| switch($action){
case"login": $form_action = ""; $input = array( "login" => array( "accept-charset" => $accept_charset ,"height" => "" ,"maxlength" => "13" ,"type" => "text" ,"width" => "" ,"class" => "" ), "pass" => array( "accept-charset" => $accept_charset ,"height" => "" ,"maxlength" => "15" ,"type" => "text" ,"width" => "" ,"class" => "" ), "button" => array( "height" => "" ,"type" => "button" ,"value" => "Ok" ,"width" => "" ,"class" => "" ) ); $form = array( "action" => $form_action ,"target" => "_self" ,"method" => "post" ); break; case"register": $form_action = ""; $input = array( "login" => array( "accept-charset" => $accept_charset ,"height" => "" ,"maxlength" => "13" ,"type" => "text" ,"width" => "" ,"class" => "" ), "pass" => array( "accept-charset" => $accept_charset ,"height" => "" ,"maxlength" => "15" ,"type" => "text" ,"width" => "" ,"class" => "" ), "confirmpass" => array( "accept-charset" => $accept_charset ,"height" => "" ,"maxlength" => "15" ,"type" => "text" ,"width" => "" ,"class" => "" ), "button" => array( "height" => "" ,"type" => "button" ,"value" => "Ok" ,"width" => "" ,"class" => "" ) ); $form = array( "action" => $form_action ,"target" => "_self" ,"method" => "post" ); break; } |
| Code: |
| $count = count($form);
$count = $count++; $a = 0; reset($form); echo "<form "; while($a!==$count){ ++$a; $key = key($form); $value = current($form); $values = " $values $key=\"$value\" "; next($form); } echo " $values >"; reset($input); $values = ""; $count = ""; $count = count($input); $count = $count++; $a = 0; while($a!==$count){ ++$a; $key = key($input); $count2 = count($input[$key]); $count2 = $count2++; $b = 0; reset($input[$key]); while($b!==$count2){ ++$b; $key2 = key($input[$key]); $value2 = current($input[$key]); $values = " $values $key2=\"$value2\" "; next($input[$key]); } next ($input); echo "<input $values >"; $values = ""; } echo "</form>"; ?> |
| psykow wrote: |
| Desculpe cara, mas como minha própria assinatura diz, sou um amador, e pra começo de conversa eu nem sei pra q serve o "->" e o "=>", foi mal mesmo. |
| sintaxe de uma array wrote: |
| A sintaxe "index => values", separados por vírgulas, definem índice e valores respectivamente. |
| mariohs wrote: |
| Uma pergunta: o número de variáveis, apesar de grande, que você passa por get é finito, não? |
| mariohs wrote: |
| Porque não cria uma variável por parâmetro e usa as variáveis dinamicamente? |
| Code: |
| $action = $_GET["action"];
$v1 = $_GET["v1"]; $v2 = $_GET["v2"]; $v3 = $_GET["v3"]; $v4 = $_GET["v4"]; $v5 = $_GET["v5"]; $v6 = $_GET["v6"]; switch ($action) { case "a1": echo "v1=$v1, v2=$v2, v3=$v3"; break; case "a2": echo "v4=$v4, v5=$v5, v6=$v6"; break; } |
| Code: |
| $text = "variavel";
$string = "new"; $$string = $text; |