Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.