473,507 Members | 8,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Notice: Undefined offset: 49

1 New Member
Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars[49]==$required)", i'm a newbie, i don't know how to overcome this error, so can someone please help me out?
thanks,
Expand|Select|Wrap|Line Numbers
  1. $string = "one two three";
  2. $word_array = explode(" ",$string);
  3. for ($i=count($word_array); $i>=1; $i--)
  4. {
  5. $word = $i == 1 ? " word" : " words";
  6. echo "Strings containing combination of ".$i.$word.":<br>";
  7.  
  8. $flags = array();
  9. $combination_flags = get_combination_flags(count($word_array), $i);
  10. $flags_groups = explode(",",$combination_flags);
  11. foreach ($flags_groups as $val)
  12. {
  13. $temp = chunk_split($val,1,".");
  14. array_push($flags, explode(".", substr($temp,0,(strlen($temp)-1))));
  15. }
  16. for ($j=0; $j<count($flags); $j++)
  17. {
  18. $new_string = "";
  19. for ($k=0; $k<count($word_array); $k++)
  20. $new_string .= $flags[$j][$k] ? " ".$word_array[$k] : "";
  21. trim ($new_string);
  22. echo $new_string."<br>";
  23. }
  24. echo "<br>";
  25. }
  26.  
  27. function get_combination_flags($total, $required)
  28. {
  29. $flag_array = array();
  30. $bin = "";
  31. for ($i=0; $i<$total; $i++)
  32. $bin .= "1";
  33. $dec = bindec($bin);
  34. for ($i=0; $i<=$dec; $i++)
  35. {
  36. $num_of_chars = count_chars(decbin($i), 1);
  37. if ($num_of_chars[49]==$required)
  38. {
  39. $temp = decbin($i);
  40. $length = strlen($temp);
  41. $pre = "";
  42. if ($length<$total) for ($j=$length; $j<$total; $j++) $pre .= "0";
  43. $temp = $pre.$temp;
  44. array_push($flag_array,$temp);
  45. }
  46. }
  47. return implode(",",$flag_array);
  48. }
  49. ?>
  50.  
Jul 3 '10 #1
1 5115
zorgi
431 Recognized Expert Contributor
All that means is that your error_reporting in your php.ini file is set to report notices. There is two ways around this problem. First one is to set your error_reporting so it doesn't report notices:

error_reporting = E_ALL & ~E_NOTICE

that way you turn off all the notices.

OR

You can use extra condition in your if statement:

Expand|Select|Wrap|Line Numbers
  1. if ((isset($num_of_chars[49]))&&($num_of_chars[49] == $required))
  2.  
Jul 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
108820
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
2
25815
by: Steven | last post by:
Hi All, I am moving some php code from a Linux machine to a Windows 2000 machine with the code belowe I get the following error : Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on...
1
4567
by: google | last post by:
Hello, I'm having major problems trying to get my head round this problem. I'm trying to generate an error free script, however, I still cannot sort out this loop. I get a "Notice:...
4
10170
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
6
4467
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in...
3
5483
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
9
32486
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
2
2676
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315...
6
18533
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error?...
3
5975
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.