Jump to content

Recommended Posts

Well I have a code that looks like this:

 

<div style='width:100%; text-align:center; float:left;'>{$array[0][0]}</div>
<div style='width:50%; text-align:center; float:left;'>{$array[1][0]}</div>
<div style='width:25%; text-align:center; float:left;'>{$array[2][0]}</div>
<div style='width:12.5%; text-align:center; float:left;'>{$array[3][0]}</div>

 

As you can see, the width percentage decreases by half as the first index of $array increases by 1. I was wondering if its possible to write a PHP code such that the width percentage is automatically adjusted based on the first index of array. I've tried the following way as below, but it wouldnt work:

 

<div style='width:{100/(2^$i)}%; text-align:center; float:left;'>{$array[$i][$j]}</div>

 

So do anyone of you know how to do this? Please help.

Link to comment
https://forums.phpfreaks.com/topic/247918-about-in-php-please-help/
Share on other sites

umm looks like it wont work, I am assuming it is impossible to write an expression to specify the width percentage? The following code works perfectly:

 

<div style='width:25%; text-align:center; float:left;'>{$array[2][0]}</div>

 

But this one wont:

<div style='width:{(100/pow(2,2))}%; text-align:center; float:left;'>{$array[2][0]}</div>

Thank you so much, it works. And btw, can I resize images based on the same mechanism?

 

<img src='{$row['avatar']}' border=0 width='50' height='25' />

 

Can be converted into this?

 

<img src='{$row['avatar']}' border=0 width=".(100/pow(2,1))." height=".(100/pow(2,2))." />

I am assuming it is impossible to write an expression to specify the width percentage?

"expressions" inside strings only work if you start with a $ (like with a variable). There are creative ways around this though:

$expr = function($value) { return $value; }; // or use create_function()
$string = "{$expr(100/4)}%";

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.