Defining a constant array in Laravel or PHP? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to define a constant of array. How can I do that?
define("CREDIT_REPORT_FAIL", "FAIL");

In Laravel you can define an array in a config file:
'some_array' => [
'var' => 'value',
'another_var' => 'value'
],
And then you config() global helper to get the array:
config('config_file.some_array')

Please Try This Code
Define Code
define('TEST', serialize(array(1, 5, 10, 15)));
Use
$data = unserialize(TEST);

Related

How to get unlimited argument without parameter limit [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
function test(){
}
test(58,1,"world","hello");
How can Use this argument test() function parameter.
Use func_get_args()
<?php
function test(){
print_r(func_get_args());
}
test(58,1,"world","hello");
Output:
Array
(
[0] => 58
[1] => 1
[2] => world
[3] => hello
)

Create serial number with 8 length digits [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to create a format like this: 0000-0000. I already i have the unique number, but i need to merge it with my format type.
$my_id_unique = '60';
//some function....
//IT SHOULD OUTPUT LIKE THIS
$create_serial = '0000-0060';
$x = sprintf("%08d",$my_id_unique);
$create_serial = substr($x,0,4).'-'.substr($x,4);
With oneliner:
$create_serial = implode('-', str_split(sprintf('%08d', $my_id_unique), 4));
Or you could use str_pad:
echo str_pad('60', 9, '0000-0000', STR_PAD_LEFT);

Is it possible to combine array variable with array number to complete 1 variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My code is as below :
assume that $a is a variable that 1 take out from DB and now i wan to combine it with an array number and produce an output that same with $box. Is it possible to do that ? or i m wrong ? please guide me.. thanks
$b="1-1-0-1";
$box=explode("-",$b);
$a="$box"; //from DB
echo $box[2];
echo "$a[1]";
Remove the quotes. Why are you so obsessed with them? https://stackoverflow.com/users/2892997/user2892997
$a=$box; //from DB
echo $box[2];
echo $a[1];
$b="1-1-0-1";
$box=explode("-",$b);
$a='$box'; //from DB
$a = substr($a, 1);
echo $box[2];
$c = $$a;
print_r($c);

PHP string assign to array variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have written some php code, trying what is to assign a string (tag_of_organization) to a variable and then latter to assign it to array newvar. As i am totally new to php and search a lot for it but cannot find anything, so i am asking it here how to do this. here it is
$organ='tag_of_organization';
$newvar = array();
$newvar["tag_of_organization"] =$organ;
Try with:
$newvar[$organ] = $organ;
You are already correct. put print_r to test print your array
$organ='tag_of_organization';
$newvar = array();
$newvar["tag_of_organization"] =$organ;
print_r($newvar);
Output
Array ( [tag_of_organization] => tag_of_organization )
Update
you want dynamic result
$organ='tag_of_organization';
$newvar = array();
$newvar[$organ] =$organ;
print_r($newvar);
Output
Array ( [tag_of_organization] => tag_of_organization )

How to remove some part of text in the first index of php array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This is my array in php
$a is my array
Array
(
[0] => class="date-display-single">24-Feb-2013
[2] => 11:35
[3] => AM
)
How do I remove class="date-display-single"> from array[0]?
Several ways... But the simplest one is to do:
$a[0] = str_replace('class="data-display-single">', '', $a[0]);
This simple statement should do exactly that:
$a[0] = substr($a[0], strpos($a[0], '>') + 1);
That said, it all depends on how you ended up with that array in the first place; it seems things can be fixed higher up in the code.
there you are:
$a[0] = str_replace('class="date-display-single">','',$a[0]);
but i would do it in the string, before you explode your date string. no in the array after
Check out unset()
You could try something like:
unset($a[0]);
Try this
str_replace('class="date-display-single">', '', $a[0]);

Categories