Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have an array what consist of arrays. Have a looks into this file gist.
How you can see each array repeats two times. I need to delete the second, I need to compare them by 'key' value of array.
Thanks!
The easiest way to get the result you expect is in my opinion this way:
$data = array(
array(
'domain' => 'messages',
'key' => 'test.testik',
'message' => array()
),
array(
'domain' => 'messages',
'key' => 'test2313.tes31231tik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'joga.jimbo',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
)
);
$newdata = array();
foreach ($data as $subdata) {
$newdata[$subdata['key']] = $subdata;
}
$newdata = array_values($newdata); // reset array indizes
print_r($newdata);
The undefined offset 6 error is telling you that there isnt an array element at position 6. Without seeing your error message and your code I cant tell you where the error is But you would need to see if the element exists using something like this:
if (isset($array[index]))
{
//do something
}
This will handle the error, meaning you wont get the message, but you should see why the element doesnt exist, like Was there a problem when the arrays were made.
Your error message will tell you which line the problem was on and therefore which array variables are causing these errors.
UPDATE:
your code will always return true as you are comparing a value to itself therefore it will be an empty array.
$transll['key'] == $transll['key']
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need help with PHP and the Stripe API.
$stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
That gives me back an answer like this:
{
"object": "account_link",
"created": 1606772720,
"expires_at": 1606773020,
"url": "https://connect.stripe.com/setup/s/QaVzgu7GNGFP"
}
I need help to know how to display the "url" in a variable in PHP.
I've tried to do this but it doesn't work:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$data = json_decode($link);
$links = $data->url;
If someone knows what I can do it would help me a lot. Thanks :)
EDIT:
The var_dump returns this:
object(Stripe\AccountLink)#127 (4) { ["object"]=> string(12) "account_link" ["created"]=> int(1606856512) ["expires_at"]=> int(1606856812) ["url"]=> string(47) "https://connect.stripe.com/setup/c/vD45DxCl0hZQ" }
But I just need url string
You do not need to json_decode the resulting account link object. All you need to do is access the URL property on the object returned by Stripe. For example:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$url = $link->url;
echo $url;
You can use the $url variable in a template or to perform any other server-side logic. The structure of the returned account link object can be referenced here:
https://stripe.com/docs/api/account_links/object
I've made it work by doing this:
$link = $stripe->accountLinks->create(
[
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]
);
$var_url = var_export($link->url, true);
$good_url = str_replace("'", "", $var_url);
Now when I echo "good_url" I get the full url successfully.
Thank you all very much, really, you have helped me a lot.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have an array which I am using some method to make an api call. I have 2 methods out of which I need to select 1 based on the session value.
My array looks like this.
$order_params = array(
'username' => 'test1',
'password' => 'test2',
'method' => 'Gateway1');
So if session value is not null than method needs to be Gateway2 and need to pass one more parameter. What I am doing is using this way to update the array.
$order_params = array(
'username' => 'test1',
'password' => 'test2',
'method' => 'Gateway1');
if($_SESSION['userid'] != ''){
$order_params['method'] = 'Gateway2';
$order_params['proid'] = '222'
}
I need to confirm if I am doing the right way, OR if there is a more better way to do this.
I need to confirm if I am doing the right way, OR if there is a more
better way to do this.
This is really hard to say without seeing all of your code, but you can tidy up the code a bit and approach it slightly differently by setting your values in one go:
$order_params = [
'username' => 'test1',
'password' => 'test2',
'method' => $_SESSION['userid'] != '' ? 'Gateway2' : 'Gateway1',
'proid' => $_SESSION['userid'] != '' ? '222' : null,
];
So set it in one go.
method is set to "Gateway2" if you have a userid, else set to the default "Gateway1"
proid is set to "222" if you have a userid, else set to the default empty (just so the array key is set and you don't later need to do if (isset($order_params['proid'])))
I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.
I need to send a SOAP request to an API that can contain an element that repeats like so:
<operationNumbers>
<operationNumber>1234</operationNumber>
<operationNumber>1235</operationNumber>
<operationNumber>1236</operationNumber>
<operationNumber>1237</operationNumber>
</operationNumbers>
I did read that perhaps I could do this:
$buildRequest = Array(
'myheader' => Array(
'date' => MY_DATE,
'id' => Array(
'client' => CLIENT,
'clientRef' => MYREF
)
),
'operationNumbers' => Array (
Array('operationNumber' => '1234'),
Array('operationNumber' => '1235')
)
);
$request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );
Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:
...
'operationNumbers' => Array (
'operationNumber' => '1234'
)
...
The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.
So, I solved it.
$operationNumbersArray = array('1234','1235');
...
'operationNumbers' => array(
'operationNumber' => $operationNumbersArray
)
During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).
Here is the code I use:
$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a question, if in my page I want to search:
- Last 10 registered users
- Last 10 login users
- Last 10 users that have inserted a product
These query are more than one, well in my controller I have to make more query and every query put it into a variable right?
something like that?
$first_query = $this->User->find ('all', array(
'conditions' => array(...)
));
$second_query = $this->User->find ('all', array(
'conditions' => array(...)
));
$third_query = $this->User->find ('all', array(
'conditions' => array(...)
));
And in my view I'll use the variables $first_query, $second_query, $third_query
Is correct or is better to divide into more function on the controller the query?
No, the way you do it is "the" way. You should probably name them differently, though, since the variables do not contain any queries, but results, and "first", "second" etc. says nothing about the content. I'd call them $lastRegisteredUsers, $lastLoggedInUsersetc.
If the conditions are very similar, like if you want to select users from only one category, or some such, you could store that condition in a variable and reuse it, instead of copy-pasting.
You can use the following code in your controller's action method:
You can map the model association with itself. And this will return you the expected result.
$this->User->bindModel(array('belongsTo' => array('LastRegUser' =>
array(
'className' => 'User',
'foreignKey' => 'id',
'conditions' => array(...)),
'LoggedInUser' => array(
'className' => 'User',
'foreignKey' => 'id',
'conditions' => array(...)) ..... )));
And then you can simple use the following code to fetch all the users using following code.
$users = $this->User->find('all');
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 got a problem for a script I'm working on: I need the array that normaly gets generated in the query_person() function to be saved in protected static $users to be used across the script. This is just a quick test I made, normally the array gets generated by a query.
The script works if I do it like this:
protected static $users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f1fb840a86a84b", 'p_id' => "10000000", 'p_md5' => "d1ca3aaf52b41acd68ebb3bf69079bd1")
);
but since the array gets generated by a db query I had to put the query in a function but it doesn't work like this then:
protected static $users = array();
public function query_personen(){
$users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
}
How do I make it work so that the second script generates the same output as the first?
public function query_personen(){
$this->users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
You need to use $this to refer to the object.
If you want it to be static, you should use:
public static function query_personen(){
self::$users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
Note that the second function is a static function (Yours in the example isn't so you should use the first version).