Jump to content

Why?


unidox

Recommended Posts

I am trying to get this to work, but its not... Whats wrong?

 

<?php
$codes_used = array(
array("Unidox", "0"),
array("Ro0t", "0"),
//<newuser>
);

function find_user($user) {
$out = false;
$cnt = count($codes_used);
$i = 0;
while ($i < $cnt) {
	if ($user == $codes_used[$i][0]) {
		$out = true;
	}
	$i++;
}
return $out;
}

if (find_user("Unidox")) {
echo "True";
} else {
echo "False";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/114025-why/
Share on other sites

Here is a good example. Play with it a bit.

 

<?php
$cds = array(
  'Christina Aguilera'=>array(
    'Impossible',
    'Beautiful',
    'Dirrty'
  ),
  'Pink'=>array(
    'Just like a pill',
    'Family potrait',
    'Missundaztood'
  ),
  'Kelly Rowland'=>array(
    'Stole',
    'Obsession',
    'Past 12'
  )
);

echo '<p><b>How many CDs in our collection?</b><br />
There are '.sizeof($cds)." CDs in our collection.</p>\n";

echo "<ol>\n";
foreach( $cds as $singer=>$songs )
{
  echo '  <li><b>'.$singer."</b>.<br />\n";
  echo "  <em>Songs</em>: </li>\n";
  echo "  <ul>\n";
  asort( $songs ); // sorts the list of songs
  foreach( $songs as $song )
  {
    echo '    <li>'.$song.".</li>\n";
  }
  echo "  </ul>\n";
}
echo "</ol>\n";

?>

Link to comment
https://forums.phpfreaks.com/topic/114025-why/#findComment-586038
Share on other sites

I tried this but still not working ....

 

<?php
$codes_used = array(
array("Unidox", "0"),
array("Ro0t", "0"),
//<newuser>
);

function find_user($user) {
$out = false;
$i = 0;
foreach ($codes_used as $cud) {
	if ($user == $cud[0]) {
		$out = true;
	}
	$i++;
}
return $out;
}

if (find_user("Unidox")) {
echo "True";
} else {
echo "False";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/114025-why/#findComment-586041
Share on other sites

$codes_used does not exist within your function.

 

<?php
$codes_used = array(
array("Unidox", "0"),
array("Ro0t", "0"),
//<newuser>
);

function find_user($user,$codes_used) {
  foreach ($codes_used as $cud) {
    if ($user == $cud[0]) {
      return true;
    }
  }
  return false;
}

if (find_user('Unidox',$codes_used)) {
  echo "found\n";
} else {
  echo "not found\n";
}

?>

 

I also cleaned your function of un required code.

Link to comment
https://forums.phpfreaks.com/topic/114025-why/#findComment-586058
Share on other sites

Archived

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

×
×
  • Create New...

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.