Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/11/2012, 15:25
Avatar de jor_0203
jor_0203
 
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
Respuesta: que significa true y false

Cita:
Iniciado por rottenp4nx Ver Mensaje
Se usa para "comprobar" datos por ejemplo

Creamos una funcion

Código PHP:
Ver original
  1. function numeroPositivo($num){
  2.     if($num > 0){
  3.        return true;
  4.     }else{
  5.        return false;
  6.     }
  7. }

y ahora preguntamos

Código PHP:
Ver original
  1. if(numeroPositivo(2)){
  2.    echo 'El numero es positivo';
  3. }
  4. else{
  5.    echo 'El numero es negativo'
  6. }

Le pasamos el numero 2 a la función

Si el num (2) es mayor a 0 retornará true la cual cumple la condición del bloque if y ejecutará en pantalla el echo

"El numero es positivo"

Espero que hayas entendido

Saludos


pero tambien en ajax se usa true y false, entonces es para decir si es verdadero o falso como este ejemplo


<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>