vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   array gone wrong. (https://vborg.vbsupport.ru/showthread.php?t=111514)

Red Blaze 03-27-2006 06:03 PM

array gone wrong.
 
This is the little piece of code I'm trying to get working.

PHP Code:

<?php
$priceids 
$row_call_albums['priceids'];
$arr = array($priceids);
foreach (
$arr as $value) {
   
$value $value 2;
   echo 
$value;
}
?>

In this case, $priceids calls 1, 2, 3.

Now, it does call it, but it doesn't loop. It does 1x2, and stops there. But if I replace "$priceids" with "1, 2, 3", it works just fine. It multiplies 1x2, then 2x2, then 3x2.

The results with $priceids in the array is just "2". But the results for "1, 2, 3" in the array is "246".

Is there a way around this issue? Thanks in advance.

sabret00the 03-27-2006 06:06 PM

try
PHP Code:

<?php
$priceids 
$row_call_albums['priceids'];
$arr = array($priceids);
print_r($arr);
/*foreach ($arr as $value) {
   $value = $value * 2;
   echo $value;
}*/
?>

if it gives you an array then?

PHP Code:

<?php
$priceids 
$row_call_albums['priceids'];
$arr = array($priceids);
foreach (
$arr as $key => $value)
{
   
$key $value 2;
   echo 
$key;
}
?>


Red Blaze 03-27-2006 06:12 PM

This is my result when I put
print_r($arr);

Array ( [0] => 1, 2, 3 )

And when I tried $arr as $key => $value, gave me the same result as before. Just plain 2.

sabret00the 03-27-2006 10:46 PM

the fix is
PHP Code:

<?php
$priceids 
$row_call_albums['priceids'];
$arr explode(" "$priceids);
foreach (
$arr as $key => $value)
{
   
$key $value 2;
   echo 
$key;
}
?>


Code Monkey 03-28-2006 01:03 AM

Quote:

Originally Posted by sabret00the
the fix is
PHP Code:

<?php
$priceids 
$row_call_albums['priceids'];
$arr explode(" "$priceids);
foreach (
$arr as $key => $value)
{
   
$key $value 2;
   echo 
$key;
}
?>


You can cut out a line of code by just using this.

PHP Code:

$arr explode(' '$row_call_albums['priceids']); 

No sense adding another variable to memory when it's not needed.

Actually, if the rusults of $row_call_albums['priceids'] has the format of 1, 2, 3 then you should explode it into array with ',' not ' '.

Paul M 03-28-2006 01:24 AM

Since they are comma seperated the explode should be using a comma, not a space ;

Quote:

$arr = explode(",", $priceids);


All times are GMT. The time now is 03:55 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01565 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete