Autor
|
Tema: [Solucionado] Duda con variables (Leído 5,844 veces)
|
xassiz_
Desconectado
Mensajes: 273
Ich werde dich töten..
|
Bueno, tengo un problema  En batch lo llaman polimetría no se si hay algo de PHP acerca de esto.. Bueno, el caso es que quiero indicar el nombre de una variable con otra variable. Ejemplo: <?php $variable = "decir"; ?>
Y quiero crear otra variable que se llame "decirhola".. <?php
$variable = "decir"; $$variablehola = "hola";
echo $decirhola;
?>
Espero entendais! Saludos
|
|
« Última modificación: 16 Mayo 2010, 14:00 pm por xassiz »
|
En línea
|
 YXVuIGVyZXMgbWF0YWRvIHBhcmEgcG9uZXJ0ZSBhIGRlc2NpZnJhciBlc3RvIHhE
|
|
|
Shell Root
|
¬¬! no entiendo el motivo de hacer eso, pero para eso esta el uso del contatenador (.)$strHola = 'Hola'; $strDecir = 'Decir'; echo $strDecir.$strHola;
|
|
|
En línea
|
Te vendería mi talento por poder dormir tranquilo.
|
|
|
xassiz_
Desconectado
Mensajes: 273
Ich werde dich töten..
|
A ver, no me entendiste, simplemente era un ejemplo. Tengo una serie de variables $algo1 $algo2 $algo3 ... Y quiero que el numero sea una variable numerica que se vaya incrementando. Para eso tendria que hacer algo tal que asi: <?php for ($i = 1;$i<=10;$i++) { echo $algo$i; } ?>
Me entiendes ahora?
|
|
|
En línea
|
 YXVuIGVyZXMgbWF0YWRvIHBhcmEgcG9uZXJ0ZSBhIGRlc2NpZnJhciBlc3RvIHhE
|
|
|
Shell Root
|
Simon, desde el inicio del POST entendí lo que quieres hacer, lo que no entiendo es el uso que le podrías dar. Dadnos un ejemplo y de allí partiremos con la solución de tu duda!
|
|
|
En línea
|
Te vendería mi talento por poder dormir tranquilo.
|
|
|
xassiz_
Desconectado
Mensajes: 273
Ich werde dich töten..
|
Tengo una lista de arrays con esa "estructura" de nombre. array_1 array_2 array_3 array_4 Hasta x numero. Y quiero mostrarlos (no se cuantos de ellos hay en total, eso varía). <?php $array_1 = array("Dato 1","Dato 2"); $array_2 = array("Dato 1","Dato 2"); $array_3 = array("Dato 1","Dato 2"); $array_4 = array("Dato 1","Dato 2"); ?>
Entonces: <?php for ($i = 1;$i<=10;$i++) { echo $array_$i[0]; echo $array_$i[1]; echo $array_$i[2]; } ?>
|
|
|
En línea
|
 YXVuIGVyZXMgbWF0YWRvIHBhcmEgcG9uZXJ0ZSBhIGRlc2NpZnJhciBlc3RvIHhE
|
|
|
cassiani
Desconectado
Mensajes: 978
« Anterior | Próximo »
|
hola, solucionalo usando una matriz de dos dimensiones: $matriz [Indice1] [Indice2] con la funcion count sabras hasta donde debes iterar
|
|
|
En línea
|
|
|
|
Shell Root
|
En tú caso xassiz, sería algo como esto: $matriz[0][0] = 'Dato 1'; $matriz[0][1] = 'Dato 2'; $matriz[1][0] = 'Dato 1'; $matriz[1][1] = 'Dato 2';
shellroot@alex-laptop:/var/www/PoC$ php index.php Array ( [0] => Array ( [0] => Dato11 [1] => Dato12 ) [1] => Array ( [0] => Dato22 [1] => Dato23 ) ) shellroot@alex-laptop:/var/www/PoC$
|
|
|
En línea
|
Te vendería mi talento por poder dormir tranquilo.
|
|
|
|
xassiz_
Desconectado
Mensajes: 273
Ich werde dich töten..
|
Voy ver si consigo hacer algo con la matriz de dos dimensiones. El problema es que no los quiero mostrar juntos, van en el código php por separado.. o con tags html por el medio >.< asi que el print_r ya no me serviria ;/
|
|
|
En línea
|
 YXVuIGVyZXMgbWF0YWRvIHBhcmEgcG9uZXJ0ZSBhIGRlc2NpZnJhciBlc3RvIHhE
|
|
|
Shell Root
|
Para eso entonces están los bucles. While, For, For Each. Por ejemplo: $matriz[0][0] = 'Dato11'; $matriz[0][1] = 'Dato12'; $matriz[1][0] = 'Dato22'; $matriz[1][1] = 'Dato23'; for ($i = 0; $i < 2; $i++){ for ($j = 0; $j < 2; $j++){ echo $matriz[$i][$j]; } echo '<br>'; }
shellroot@alex-laptop:/var/www/PoC$ php index.php Dato11Dato12 Dato22Dato23 shellroot@alex-laptop:/var/www/PoC$
|
|
« Última modificación: 15 Mayo 2010, 01:06 am por Alex@ShellRoot »
|
En línea
|
Te vendería mi talento por poder dormir tranquilo.
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
[PROBLEMA] Concatenar variables. [SOLUCIONADO]
Programación C/C++
|
Siquillote
|
8
|
8,456
|
27 Diciembre 2010, 14:12 pm
por Siquillote
|
|
|
Problemas de variables creando bat desde bat[Solucionado]
Scripting
|
Peebbles
|
2
|
2,946
|
13 Enero 2011, 17:46 pm
por Peebbles
|
|
|
[SOLUCIONADO] Una ayuda sobre las variables dinámicas
.NET (C#, VB.NET, ASP)
|
Eleкtro
|
0
|
1,887
|
6 Enero 2013, 00:46 am
por Eleкtro
|
|
|
SOLUCIONADO - Comparar 3 variables
PHP
|
WiseHidden
|
6
|
6,477
|
26 Septiembre 2013, 17:21 pm
por 1mpuls0
|
|
|
[SOLUCIONADO] Ayuda: Node.js ambito de variables
Desarrollo Web
|
patilanz
|
5
|
4,177
|
29 Noviembre 2017, 05:32 am
por Luis Leon B
|
|